-
-
Notifications
You must be signed in to change notification settings - Fork 77
Add option to disable span activation #1187
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
Changes from 3 commits
d1b5118
125dc51
63a194a
a133129
9069ce6
69e9c39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,13 +175,18 @@ object Span { | |
| def spanKind: Span.SpanKind | ||
| def links: Chain[Kernel] | ||
|
|
||
| /** Whether to activate span in underlying tracing framework. This typically binds span to a ThreadLocal. */ | ||
| def activateSpan: Boolean | ||
|
||
|
|
||
| def withParentKernel(kernel: Kernel): Options | ||
| def withoutParentKernel: Options | ||
| def withSpanCreationPolicy(p: Options.SpanCreationPolicy): Options | ||
|
|
||
| def withSpanKind(spanKind: SpanKind): Options | ||
|
|
||
| def withLink(kernel: Kernel): Options | ||
|
|
||
| def withActivateSpan(activateSpan: Boolean): Options | ||
| } | ||
|
|
||
| object Options { | ||
|
|
@@ -202,22 +207,25 @@ object Span { | |
| parentKernel: Option[Kernel], | ||
| spanCreationPolicy: SpanCreationPolicy, | ||
| spanKind: SpanKind, | ||
| links: Chain[Kernel] | ||
| links: Chain[Kernel], | ||
| activateSpan: Boolean | ||
| ) extends Options { | ||
| override def withParentKernel(kernel: Kernel): Options = | ||
| OptionsImpl(Some(kernel), spanCreationPolicy, spanKind, links) | ||
| OptionsImpl(Some(kernel), spanCreationPolicy, spanKind, links, activateSpan) | ||
|
||
| override def withoutParentKernel: Options = | ||
| OptionsImpl(None, spanCreationPolicy, spanKind, links) | ||
| OptionsImpl(None, spanCreationPolicy, spanKind, links, activateSpan) | ||
| override def withSpanCreationPolicy(p: SpanCreationPolicy): Options = | ||
| OptionsImpl(parentKernel, p, spanKind, links) | ||
| OptionsImpl(parentKernel, p, spanKind, links, activateSpan) | ||
| override def withSpanKind(spanKind: SpanKind): Options = | ||
| OptionsImpl(parentKernel, spanCreationPolicy, spanKind, links) | ||
| OptionsImpl(parentKernel, spanCreationPolicy, spanKind, links, activateSpan) | ||
| override def withLink(kernel: Kernel): Options = | ||
| OptionsImpl(parentKernel, spanCreationPolicy, spanKind, links.append(kernel)) | ||
| OptionsImpl(parentKernel, spanCreationPolicy, spanKind, links.append(kernel), activateSpan) | ||
| override def withActivateSpan(activateSpan: Boolean): Options = | ||
| OptionsImpl(parentKernel, spanCreationPolicy, spanKind, links, activateSpan) | ||
| } | ||
|
|
||
| val Defaults: Options = | ||
| OptionsImpl(None, SpanCreationPolicy.Default, SpanKind.Internal, Chain.empty) | ||
| OptionsImpl(None, SpanCreationPolicy.Default, SpanKind.Internal, Chain.empty, true) | ||
|
||
| val Suppress: Options = Defaults.withSpanCreationPolicy(SpanCreationPolicy.Suppress) | ||
| val Coalesce: Options = Defaults.withSpanCreationPolicy(SpanCreationPolicy.Coalesce) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,9 @@ final class DDEntryPoint[F[_]: Sync](tracer: ot.Tracer, uriPrefix: Option[URI]) | |
| Resource | ||
| .make(initSpan())(s => Sync[F].delay(s.finish())) | ||
| .flatTap(span => | ||
| Resource.make(Sync[F].delay(tracer.activateSpan(span)))(s => Sync[F].delay(s.close())) | ||
| Resource | ||
| .make(Sync[F].delay(tracer.activateSpan(span)))(s => Sync[F].delay(s.close())) | ||
| .whenA(options.activateSpan) | ||
| ) | ||
| .map(DDSpan(tracer, _, uriPrefix, options)) | ||
| } | ||
|
|
@@ -52,7 +54,9 @@ final class DDEntryPoint[F[_]: Sync](tracer: ot.Tracer, uriPrefix: Option[URI]) | |
| Resource | ||
| .make(initSpan())(s => Sync[F].delay(s.finish())) | ||
| .flatTap(span => | ||
| Resource.make(Sync[F].delay(tracer.activateSpan(span)))(s => Sync[F].delay(s.close())) | ||
| Resource | ||
| .make(Sync[F].delay(tracer.activateSpan(span)))(s => Sync[F].delay(s.close())) | ||
| .whenA(options.activateSpan) | ||
|
||
| ) | ||
| .map(DDSpan(tracer, _, uriPrefix, options)) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't had a chance to fully look at this PR yet, but is there any way to achieve this without an early-semver-major version bump?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I would have to provide default noop implementations in the trait?
I.e.
def withActivateSpan(b: Boolean) = this. Not sure if this makes sense.I wish I knew how to test it without waiting for PR checks.
I've tried
sbt ++2.13.16 mimaReportBinaryIssuesas per https://typelevel.org/cats/contributing.html but it's not working: