Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.typesafe.tools.mima.core._

ThisBuild / tlBaseVersion := "0.3"
ThisBuild / tlBaseVersion := "0.4"
Copy link
Member

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?

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 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 mimaReportBinaryIssues as per https://typelevel.org/cats/contributing.html but it's not working:

[info] natchez-core: mimaPreviousArtifacts is empty, not analyzing binary compatibility.


val scala212Version = "2.12.20"
val scala213Version = "2.13.16"
Expand Down
36 changes: 28 additions & 8 deletions modules/core/shared/src/main/scala/Span.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,25 @@ object Span {
def spanKind: Span.SpanKind
def links: Chain[Kernel]

def shouldActivateSpan: 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

/** Whether to activate span in underlying tracing framework when starting the span.
*
* Note that span activation typically uses `ThreadLocal` and will be incorrect if your code shifts threads such as
* when using `IO`. Underlying tracing library might have some instrumentation to compensate for this, but it won't
* necessarily work correctly.
*
* This is the default behavior.
*/
def withShouldActivateSpan(shouldActivateSpan: Boolean): Options
}

object Options {
Expand All @@ -202,22 +214,30 @@ object Span {
parentKernel: Option[Kernel],
spanCreationPolicy: SpanCreationPolicy,
spanKind: SpanKind,
links: Chain[Kernel]
links: Chain[Kernel],
shouldActivateSpan: Boolean
) extends Options {
override def withParentKernel(kernel: Kernel): Options =
OptionsImpl(Some(kernel), spanCreationPolicy, spanKind, links)
copy(parentKernel = Some(kernel))
override def withoutParentKernel: Options =
OptionsImpl(None, spanCreationPolicy, spanKind, links)
copy(parentKernel = None)
override def withSpanCreationPolicy(p: SpanCreationPolicy): Options =
OptionsImpl(parentKernel, p, spanKind, links)
copy(spanCreationPolicy = p)
override def withSpanKind(spanKind: SpanKind): Options =
OptionsImpl(parentKernel, spanCreationPolicy, spanKind, links)
copy(spanKind = spanKind)
override def withLink(kernel: Kernel): Options =
OptionsImpl(parentKernel, spanCreationPolicy, spanKind, links.append(kernel))
copy(links = links.append(kernel))
override def withShouldActivateSpan(shouldActivateSpan: Boolean): Options =
copy(shouldActivateSpan = shouldActivateSpan)
}

val Defaults: Options =
OptionsImpl(None, SpanCreationPolicy.Default, SpanKind.Internal, Chain.empty)
val Defaults: Options = OptionsImpl(
None,
SpanCreationPolicy.Default,
SpanKind.Internal,
Chain.empty,
shouldActivateSpan = true
)
val Suppress: Options = Defaults.withSpanCreationPolicy(SpanCreationPolicy.Suppress)
val Coalesce: Options = Defaults.withSpanCreationPolicy(SpanCreationPolicy.Coalesce)

Expand Down
8 changes: 6 additions & 2 deletions modules/datadog/src/main/scala/DDEntryPoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.shouldActivateSpan)
)
.map(DDSpan(tracer, _, uriPrefix, options))
}
Expand All @@ -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.shouldActivateSpan)
)
.map(DDSpan(tracer, _, uriPrefix, options))
}
Expand Down
5 changes: 5 additions & 0 deletions modules/datadog/src/main/scala/DDSpan.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ final case class DDSpan[F[_]: Sync](
case (span, ExitCase.Errored(e)) => Sync[F].delay(span.log(e.toString).finish())
case (span, _) => Sync[F].delay(span.finish())
}
.flatTap(span =>
Resource
.make(Sync[F].delay(tracer.activateSpan(span)))(s => Sync[F].delay(s.close()))
.whenA(options.shouldActivateSpan)
)
.map(DDSpan(tracer, _, uriPrefix, options))
)

Expand Down