Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace sdk: add StatusData #360

Merged
merged 1 commit into from
Nov 15, 2023
Merged

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented Nov 10, 2023

@iRevive iRevive assigned iRevive and unassigned iRevive Nov 10, 2023
@iRevive iRevive added tracing Improvements to tracing module sdk module Features and improvements to the sdk module labels Nov 10, 2023
@iRevive
Copy link
Contributor Author

iRevive commented Nov 10, 2023

The spec says:

Description MUST only be used with the Error StatusCode value.

Should we encode StatusData as ADT instead? For example:

sealed abstract class StatusData(val code: StatusCode, description: Option[String])

object StatusData {
  case object Ok extends StatusData(StatusCode.Ok, None)
  case object Unset extends StatusData(StatusCode.Unset, None)
  final case class Error(desc: Option[String]) extends StatusData(StatusCode.Error, desc)
}

@armanbilge
Copy link
Member

Sure, I might do something like this.

sealed abstract class StatusData(val code: StatusCode) {
  def description: Option[String]
}

object StatusData {
  case object Ok extends StatusData(StatusCode.Ok) {
    def description: None.type = None
  }
  case object Unset extends StatusData(StatusCode.Unset) {
    def description: None.type = None
  }
  final case class Error(description: Option[String]) extends StatusData(StatusCode.Error)
}

@iRevive iRevive force-pushed the sdk-trace/status-data branch 2 times, most recently from a9482fa to 1f28bc4 Compare November 10, 2023 19:21
* the description of the [[StatusData]]. Effective only for the
* [[org.typelevel.otel4s.trace.Status.Error Status.Error]].
*/
def apply(status: Status, description: String): StatusData =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, we can move them to the SdkSpanBackend

@iRevive iRevive changed the title trace sdk: add StatusData trace sdk: add Status Nov 11, 2023
@iRevive iRevive changed the title trace sdk: add Status trace sdk: add StatusData Nov 13, 2023
Hash.by(a => (a.status, a.description))

implicit val statusDataShow: Show[StatusData] = Show.show { data =>
show"StatusData{status=${data.status}, description=${data.description}}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better to leave out description entirely if it's None?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, thanks

Comment on lines 84 to 97
test("use const instances when the given description is empty") {
Prop.forAll(statusGen) { status =>
val expected = status match {
case Status.Ok => StatusData.Ok
case Status.Error => StatusData.Error(None)
case Status.Unset => StatusData.Unset
}

assertEquals(StatusData(status), expected)
assertEquals(StatusData(status, ""), expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't really const for Error, and isn't testing that the other two are constant (should assert(StatusData(...) eq expected))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the test

@iRevive iRevive merged commit 98ae9fc into typelevel:main Nov 15, 2023
10 checks passed
@iRevive iRevive deleted the sdk-trace/status-data branch November 15, 2023 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sdk module Features and improvements to the sdk module tracing Improvements to tracing module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants