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

sdk-trace: add SdkSpanBackend #395

Merged
merged 3 commits into from
Dec 8, 2023

Conversation

iRevive
Copy link
Contributor

@iRevive iRevive commented Dec 6, 2023

Reference Link
Java implementation SdkSpan.java

@iRevive iRevive added tracing Improvements to tracing module sdk module Features and improvements to the sdk module labels Dec 6, 2023
private[trace] final class SdkSpanBackend[F[_]: Monad: Clock: Console] private (
spanProcessor: SpanProcessor[F],
immutableState: SdkSpanBackend.ImmutableState,
mutableState: AtomicCell[F, SdkSpanBackend.MutableState]
Copy link
Member

Choose a reason for hiding this comment

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

Can this be a Ref instead of an AtomicCell?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it can

Comment on lines +163 to +166
Console[F]
.println(
s"SdkSpanBackend: calling [$method] on the ended span $context"
)
Copy link
Member

Choose a reason for hiding this comment

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

Since Console is not a real logger and a lot of users might just pass the default, is this annoying? Or was it just for debugging?

Copy link
Contributor Author

@iRevive iRevive Dec 6, 2023

Choose a reason for hiding this comment

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

It shouldn't be logged often. If a user uses a library in a general way, these messages will not be logged at all.

The log message may occur if you try to update the span that has already ended.

For example:

for {
  escapedSpan <- Tracer[F].span("my-span").use { span =>
    IO.pure(span)
  }
  _ <- escapedSpan.updateName("new name") // <- 'SdkSpanBackend: calling [updateName] on the ended span ...' will be logged
} yield ()

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, right. But it doesn't serious enough to be an errorln I suppose.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can hide these warnings behind a config (e.g. traceProvider.enableConsoleWarnings).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, right. But it doesn't serious enough to be an errorln I suppose.

yeah. If we had a proper logging system, I would use warn.

}

private def addTimedEvent(event: EventData): F[Unit] =
updateState("addEvent")(s => s.copy(events = s.events :+ event)).void
Copy link
Member

Choose a reason for hiding this comment

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

events is a List, isn't this pretty inefficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Valid point. Let's use Vector under the hood.

Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

Seems good, didn't look closely at everything, it's private anyway.

@iRevive iRevive merged commit 2f506bb into typelevel:main Dec 8, 2023
10 checks passed
@iRevive iRevive deleted the sdk-trace/sdk-span-backend branch December 8, 2023 11:45
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.

2 participants