diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-08-14 17:30:16 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2017-08-14 17:30:16 +0200 |
commit | 3a8c0fa25f12230b27e943d1fffe07f814c650fe (patch) | |
tree | 75a12128af7387f40e3eba040812e1bd87b9a455 /kamon-core/src/test/scala/kamon | |
parent | a6113cf33ba1b98cc73d35176ccf8a2f76b77875 (diff) | |
download | Kamon-3a8c0fa25f12230b27e943d1fffe07f814c650fe.tar.gz Kamon-3a8c0fa25f12230b27e943d1fffe07f814c650fe.tar.bz2 Kamon-3a8c0fa25f12230b27e943d1fffe07f814c650fe.zip |
implement Span propagation on top of Kamon.Context
Diffstat (limited to 'kamon-core/src/test/scala/kamon')
-rw-r--r-- | kamon-core/src/test/scala/kamon/context/ContextCodecSpec.scala | 18 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/testkit/SpanBuilding.scala | 6 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/testkit/SpanInspector.scala | 8 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala | 65 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/ExtendedB3SpanContextCodecSpec.scala | 103 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/LocalSpanSpec.scala (renamed from kamon-core/src/test/scala/kamon/trace/RealSpanSpec.scala) | 82 | ||||
-rw-r--r-- | kamon-core/src/test/scala/kamon/trace/TracerSpec.scala | 83 |
7 files changed, 77 insertions, 288 deletions
diff --git a/kamon-core/src/test/scala/kamon/context/ContextCodecSpec.scala b/kamon-core/src/test/scala/kamon/context/ContextCodecSpec.scala new file mode 100644 index 00000000..242c3345 --- /dev/null +++ b/kamon-core/src/test/scala/kamon/context/ContextCodecSpec.scala @@ -0,0 +1,18 @@ +package kamon.context + +import kamon.Kamon +import org.scalatest.{Matchers, WordSpec} + +class ContextCodecSpec extends WordSpec with Matchers { + "the Context Codec" when { + "encoding/decoding to HttpHeaders" should { + "encode stuff" in { + + + + } + } + } + + val ContextCodec = new Codec(Kamon.config()) +} diff --git a/kamon-core/src/test/scala/kamon/testkit/SpanBuilding.scala b/kamon-core/src/test/scala/kamon/testkit/SpanBuilding.scala index 9b845ac9..29678b34 100644 --- a/kamon-core/src/test/scala/kamon/testkit/SpanBuilding.scala +++ b/kamon-core/src/test/scala/kamon/testkit/SpanBuilding.scala @@ -1,6 +1,6 @@ package kamon.testkit -import kamon.trace.SpanContext.{SamplingDecision, Source} +import kamon.trace.SpanContext.SamplingDecision import kamon.trace.{IdentityProvider, SpanContext, SpanContextCodec} trait SpanBuilding { @@ -12,9 +12,7 @@ trait SpanBuilding { traceID = identityProvider.traceIdentifierGenerator().generate(), spanID = identityProvider.spanIdentifierGenerator().generate(), parentID = identityProvider.spanIdentifierGenerator().generate(), - samplingDecision = samplingDecision, - baggage = SpanContext.Baggage(), - source = Source.Local + samplingDecision = samplingDecision ) } diff --git a/kamon-core/src/test/scala/kamon/testkit/SpanInspector.scala b/kamon-core/src/test/scala/kamon/testkit/SpanInspector.scala index ab58e446..f23fba98 100644 --- a/kamon-core/src/test/scala/kamon/testkit/SpanInspector.scala +++ b/kamon-core/src/test/scala/kamon/testkit/SpanInspector.scala @@ -10,10 +10,10 @@ import scala.util.Try class SpanInspector(span: Span) { private val (realSpan, spanData) = Try { val realSpan = span match { - case _: Span.Real => span + case _: Span.Local => span } - val spanData = invoke[Span.Real, FinishedSpan](realSpan, "toFinishedSpan", classOf[Long] -> Long.box(Clock.microTimestamp())) + val spanData = invoke[Span.Local, FinishedSpan](realSpan, "toFinishedSpan", classOf[Long] -> Long.box(Clock.microTimestamp())) (realSpan, spanData) }.getOrElse((null, null)) @@ -27,10 +27,10 @@ class SpanInspector(span: Span) { spanData.tags def metricTags(): Map[String, String] = - getField[Span.Real, Map[String, String]](realSpan, "customMetricTags") + getField[Span.Local, Map[String, String]](realSpan, "customMetricTags") def startTimestamp(): Long = - getField[Span.Real, Long](realSpan, "startTimestampMicros") + getField[Span.Local, Long](realSpan, "startTimestampMicros") def context(): SpanContext = spanData.context diff --git a/kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala b/kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala deleted file mode 100644 index a6a7bc3a..00000000 --- a/kamon-core/src/test/scala/kamon/trace/ActiveSpanManagementSpec.scala +++ /dev/null @@ -1,65 +0,0 @@ -package kamon.trace - -import kamon.Kamon -import kamon.testkit.SpanInspector -import kamon.trace.Span.Annotation -import kamon.util.Clock -import org.scalatest.{Matchers, WordSpec} - -class ActiveSpanManagementSpec extends WordSpec with Matchers { - - "Kamon acting as a ActiveSpanSource" should { - "return a empty span when there is no currently active Span" in { - inspect(Kamon.activeSpan()) shouldBe empty - } - - "safely operate on a empty Span" in { - val emptySpan = Kamon.activeSpan() - val activeSpanData = inspect(Kamon.activeSpan()) - activeSpanData shouldBe empty - - emptySpan - .setOperationName("test") - .addBaggage("key", "value") - .addMetricTag("key", "value") - .addSpanTag("string", "string") - .addSpanTag("number", 42) - .addSpanTag("boolean-true", true) - .addSpanTag("boolean-false", false) - .annotate(Annotation(Clock.microTimestamp(), "event", Map("k" -> "v"))) - - val baggage = emptySpan.context().baggage - baggage.add("key", "value") - baggage.get("key") shouldBe empty - baggage.getAll() shouldBe empty - - Kamon.withActiveSpan(emptySpan) { - inspect(Kamon.activeSpan()) shouldBe empty - } - - inspect(Kamon.activeSpan()) shouldBe empty - } - - "set a Span as active when using activate" in { - val span = Kamon.buildSpan("mySpan").start() - val scope = Kamon.activate(span) - Kamon.activeSpan() shouldBe theSameInstanceAs(span) - scope.close() - } - - "restore the previously active Span when a scope is closed" in { - val previouslyActiveSpan = Kamon.activeSpan() - inspect(Kamon.activeSpan()) shouldBe empty - - val span = Kamon.buildSpan("mySpan").start() - Kamon.withActiveSpan(span) { - Kamon.activeSpan() shouldBe theSameInstanceAs(span) - } - - Kamon.activeSpan() shouldBe theSameInstanceAs(previouslyActiveSpan) - } - } - - def inspect(span: Span): SpanInspector = - SpanInspector(span) -} diff --git a/kamon-core/src/test/scala/kamon/trace/ExtendedB3SpanContextCodecSpec.scala b/kamon-core/src/test/scala/kamon/trace/ExtendedB3SpanContextCodecSpec.scala index 24cb7ef5..cc886bd9 100644 --- a/kamon-core/src/test/scala/kamon/trace/ExtendedB3SpanContextCodecSpec.scala +++ b/kamon-core/src/test/scala/kamon/trace/ExtendedB3SpanContextCodecSpec.scala @@ -16,6 +16,7 @@ package kamon.trace +import kamon.context.{Context, TextMap} import kamon.testkit.SpanBuilding import kamon.trace.IdentityProvider.Identifier import kamon.trace.SpanContext.SamplingDecision @@ -28,38 +29,22 @@ class ExtendedB3SpanContextCodecSpec extends WordSpecLike with Matchers with Opt "The ExtendedB3 SpanContextCodec" should { "return a TextMap containing the SpanContext data" in { - val context = testSpanContext() - context.baggage.add("some", "baggage") - context.baggage.add("more", "baggage") + val context = testContext() - val textMap = extendedB3Codec.inject(context) + val textMap = extendedB3Codec.encode(context) textMap.get("X-B3-TraceId").value shouldBe "1234" textMap.get("X-B3-ParentSpanId").value shouldBe "2222" textMap.get("X-B3-SpanId").value shouldBe "4321" textMap.get("X-B3-Sampled").value shouldBe "1" - textMap.get("X-B3-Extra-Baggage").value shouldBe "some=baggage;more=baggage" } - "allow to provide the TextMap to be used for encoding" in { - val context = testSpanContext() - context.baggage.add("some", "baggage") - context.baggage.add("more", "baggage") - val textMap = TextMap.Default() - extendedB3Codec.inject(context, textMap) - textMap.get("X-B3-TraceId").value shouldBe "1234" - textMap.get("X-B3-ParentSpanId").value shouldBe "2222" - textMap.get("X-B3-SpanId").value shouldBe "4321" - textMap.get("X-B3-Sampled").value shouldBe "1" - textMap.get("X-B3-Extra-Baggage").value shouldBe "some=baggage;more=baggage" - } - - "not inject anything if the SpanContext is empty" in { - val textMap = extendedB3Codec.inject(SpanContext.EmptySpanContext) + "not inject anything if there is no Span in the Context" in { + val textMap = extendedB3Codec.encode(Context.Empty) textMap.values shouldBe empty } - "extract a SpanContext from a TextMap when all fields are set" in { + "extract a RemoteSpan from a TextMap when all fields are set" in { val textMap = TextMap.Default() textMap.put("X-B3-TraceId", "1234") textMap.put("X-B3-ParentSpanId", "2222") @@ -67,15 +52,11 @@ class ExtendedB3SpanContextCodecSpec extends WordSpecLike with Matchers with Opt textMap.put("X-B3-Sampled", "1") textMap.put("X-B3-Extra-Baggage", "some=baggage;more=baggage") - val spanContext = extendedB3Codec.extract(textMap).value + val spanContext = extendedB3Codec.decode(textMap, Context.Empty).get(Span.ContextKey).context() spanContext.traceID.string shouldBe "1234" spanContext.spanID.string shouldBe "4321" spanContext.parentID.string shouldBe "2222" spanContext.samplingDecision shouldBe SamplingDecision.Sample - spanContext.baggage.getAll() should contain allOf( - "some" -> "baggage", - "more" -> "baggage" - ) } "decode the sampling decision based on the X-B3-Sampled header" in { @@ -93,19 +74,27 @@ class ExtendedB3SpanContextCodecSpec extends WordSpecLike with Matchers with Opt noSamplingTextMap.put("X-B3-TraceId", "1234") noSamplingTextMap.put("X-B3-SpanId", "4321") - extendedB3Codec.extract(sampledTextMap).value.samplingDecision shouldBe SamplingDecision.Sample - extendedB3Codec.extract(notSampledTextMap).value.samplingDecision shouldBe SamplingDecision.DoNotSample - extendedB3Codec.extract(noSamplingTextMap).value.samplingDecision shouldBe SamplingDecision.Unknown + extendedB3Codec.decode(sampledTextMap, Context.Empty) + .get(Span.ContextKey).context().samplingDecision shouldBe SamplingDecision.Sample + + extendedB3Codec.decode(notSampledTextMap, Context.Empty) + .get(Span.ContextKey).context().samplingDecision shouldBe SamplingDecision.DoNotSample + + extendedB3Codec.decode(noSamplingTextMap, Context.Empty) + .get(Span.ContextKey).context().samplingDecision shouldBe SamplingDecision.Unknown } "not include the X-B3-Sampled header if the sampling decision is unknown" in { - val sampledSpanContext = testSpanContext() - val notSampledSpanContext = testSpanContext().copy(samplingDecision = SamplingDecision.DoNotSample) - val unknownSamplingSpanContext = testSpanContext().copy(samplingDecision = SamplingDecision.Unknown) - - extendedB3Codec.inject(sampledSpanContext).get("X-B3-Sampled").value shouldBe("1") - extendedB3Codec.inject(notSampledSpanContext).get("X-B3-Sampled").value shouldBe("0") - extendedB3Codec.inject(unknownSamplingSpanContext).get("X-B3-Sampled") shouldBe empty + val context = testContext() + val sampledSpanContext = context.get(Span.ContextKey).context() + val notSampledSpanContext = Context.Empty.withKey(Span.ContextKey, + Span.Remote(sampledSpanContext.copy(samplingDecision = SamplingDecision.DoNotSample))) + val unknownSamplingSpanContext = Context.Empty.withKey(Span.ContextKey, + Span.Remote(sampledSpanContext.copy(samplingDecision = SamplingDecision.Unknown))) + + extendedB3Codec.encode(context).get("X-B3-Sampled").value shouldBe("1") + extendedB3Codec.encode(notSampledSpanContext).get("X-B3-Sampled").value shouldBe("0") + extendedB3Codec.encode(unknownSamplingSpanContext).get("X-B3-Sampled") shouldBe empty } "use the Debug flag to override the sampling decision, if provided." in { @@ -115,7 +104,7 @@ class ExtendedB3SpanContextCodecSpec extends WordSpecLike with Matchers with Opt textMap.put("X-B3-Sampled", "0") textMap.put("X-B3-Flags", "1") - val spanContext = extendedB3Codec.extract(textMap).value + val spanContext = extendedB3Codec.decode(textMap, Context.Empty).get(Span.ContextKey).context() spanContext.samplingDecision shouldBe SamplingDecision.Sample } @@ -125,7 +114,7 @@ class ExtendedB3SpanContextCodecSpec extends WordSpecLike with Matchers with Opt textMap.put("X-B3-SpanId", "4321") textMap.put("X-B3-Flags", "1") - val spanContext = extendedB3Codec.extract(textMap).value + val spanContext = extendedB3Codec.decode(textMap, Context.Empty).get(Span.ContextKey).context() spanContext.samplingDecision shouldBe SamplingDecision.Sample } @@ -134,12 +123,11 @@ class ExtendedB3SpanContextCodecSpec extends WordSpecLike with Matchers with Opt textMap.put("X-B3-TraceId", "1234") textMap.put("X-B3-SpanId", "4321") - val spanContext = extendedB3Codec.extract(textMap).value + val spanContext = extendedB3Codec.decode(textMap, Context.Empty).get(Span.ContextKey).context() spanContext.traceID.string shouldBe "1234" spanContext.spanID.string shouldBe "4321" spanContext.parentID shouldBe IdentityProvider.NoIdentifier spanContext.samplingDecision shouldBe SamplingDecision.Unknown - spanContext.baggage.getAll() shouldBe empty } "do not extract a SpanContext if Trace ID and Span ID are not provided" in { @@ -157,34 +145,26 @@ class ExtendedB3SpanContextCodecSpec extends WordSpecLike with Matchers with Opt noIds.put("X-B3-Sampled", "0") noIds.put("X-B3-Flags", "1") - extendedB3Codec.extract(onlyTraceID) shouldBe empty - extendedB3Codec.extract(onlySpanID) shouldBe empty - extendedB3Codec.extract(noIds) shouldBe empty + extendedB3Codec.decode(onlyTraceID, Context.Empty).get(Span.ContextKey) shouldBe Span.Empty + extendedB3Codec.decode(onlySpanID, Context.Empty).get(Span.ContextKey) shouldBe Span.Empty + extendedB3Codec.decode(noIds, Context.Empty).get(Span.ContextKey) shouldBe Span.Empty } - "round trip a SpanContext from TextMap -> SpanContext -> TextMap" in { + "round trip a Span from TextMap -> Context -> TextMap" in { val textMap = TextMap.Default() textMap.put("X-B3-TraceId", "1234") textMap.put("X-B3-ParentSpanId", "2222") textMap.put("X-B3-SpanId", "4321") textMap.put("X-B3-Sampled", "1") - textMap.put("X-B3-Extra-Baggage", "some=baggage;more=baggage") - val spanContext = extendedB3Codec.extract(textMap).value - val injectTextMap = extendedB3Codec.inject(spanContext) + val context = extendedB3Codec.decode(textMap, Context.Empty) + val injectTextMap = extendedB3Codec.encode(context) textMap.values.toSeq should contain theSameElementsAs(injectTextMap.values.toSeq) } - "round trip a baggage that has special characters in there" in { - val spanContext = testSpanContext() - spanContext.baggage.add("key-with-!specials", "value=with~spec;als") - - val textMap = extendedB3Codec.inject(spanContext) - val extractedSpanContext = extendedB3Codec.extract(textMap).value - extractedSpanContext.baggage.getAll().values.toSeq should contain theSameElementsAs(spanContext.baggage.getAll().values.toSeq) - } - + /* + // TODO: Should we be supporting this use case? maybe even have the concept of Debug requests ourselves? "internally carry the X-B3-Flags value so that it can be injected in outgoing requests" in { val textMap = TextMap.Default() textMap.put("X-B3-TraceId", "1234") @@ -192,19 +172,22 @@ class ExtendedB3SpanContextCodecSpec extends WordSpecLike with Matchers with Opt textMap.put("X-B3-SpanId", "4321") textMap.put("X-B3-Sampled", "1") textMap.put("X-B3-Flags", "1") - textMap.put("X-B3-Extra-Baggage", "some=baggage;more=baggage") val spanContext = extendedB3Codec.extract(textMap).value val injectTextMap = extendedB3Codec.inject(spanContext) injectTextMap.get("X-B3-Flags").value shouldBe("1") - } + }*/ } - def testSpanContext(): SpanContext = - createSpanContext().copy( + def testContext(): Context = { + val spanContext = createSpanContext().copy( traceID = Identifier("1234", Array[Byte](1, 2, 3, 4)), spanID = Identifier("4321", Array[Byte](4, 3, 2, 1)), parentID = Identifier("2222", Array[Byte](2, 2, 2, 2)) ) + + Context.create().withKey(Span.ContextKey, Span.Remote(spanContext)) + } + }
\ No newline at end of file diff --git a/kamon-core/src/test/scala/kamon/trace/RealSpanSpec.scala b/kamon-core/src/test/scala/kamon/trace/LocalSpanSpec.scala index e019e15a..e24f8727 100644 --- a/kamon-core/src/test/scala/kamon/trace/RealSpanSpec.scala +++ b/kamon-core/src/test/scala/kamon/trace/LocalSpanSpec.scala @@ -8,7 +8,7 @@ import org.scalatest.concurrent.Eventually import org.scalatest.{BeforeAndAfterAll, Matchers, OptionValues, WordSpec} import org.scalatest.time.SpanSugar._ -class RealSpanSpec extends WordSpec with Matchers with BeforeAndAfterAll with Eventually with OptionValues +class LocalSpanSpec extends WordSpec with Matchers with BeforeAndAfterAll with Eventually with OptionValues with Reconfigure with MetricInspection { "a real span" when { @@ -37,7 +37,6 @@ class RealSpanSpec extends WordSpec with Matchers with BeforeAndAfterAll with Ev .withSpanTag("builder-number-tag", 42) .withStartTimestamp(100) .start() - .addBaggage("baggage", "value") .addSpanTag("span-string-tag", "value") .addSpanTag("span-boolean-tag-true", true) .addSpanTag("span-boolean-tag-false", false) @@ -81,87 +80,8 @@ class RealSpanSpec extends WordSpec with Matchers with BeforeAndAfterAll with Ev val customAnnotationTwo = annotations("custom-annotation-2").head customAnnotationTwo.timestampMicros shouldBe (4201) customAnnotationTwo.fields shouldBe (Map("custom" -> "yes-2")) - - finishedSpan.context.baggage.getAll() should contain( - "baggage" -> "value" - ) - } - } - - "pass all the tags, annotations and baggage to the FinishedSpan instance when started, activated and finished" in { - val scope = Kamon.activate(Kamon.buildSpan("full-span") - .withSpanTag("builder-string-tag", "value") - .withSpanTag("builder-boolean-tag-true", true) - .withSpanTag("builder-boolean-tag-false", false) - .withSpanTag("builder-number-tag", 42) - .withStartTimestamp(100) - .start()) - - Kamon.activeSpan() - .addBaggage("baggage", "value") - .addSpanTag("span-string-tag", "value") - .addSpanTag("span-boolean-tag-true", true) - .addSpanTag("span-boolean-tag-false", false) - .addSpanTag("span-number-tag", 42) - .annotate("simple-annotation") - .annotate("regular-annotation", Map("data" -> "something")) - .annotate(4200, "custom-annotation-1", Map("custom" -> "yes-1")) - .annotate(Annotation(4201, "custom-annotation-2", Map("custom" -> "yes-2"))) - .setOperationName("fully-populated-active-span") - .finish(200) - - scope.close() - - eventually(timeout(2 seconds)) { - val finishedSpan = reporter.nextSpan().value - finishedSpan.operationName shouldBe ("fully-populated-active-span") - finishedSpan.startTimestampMicros shouldBe 100 - finishedSpan.endTimestampMicros shouldBe 200 - finishedSpan.tags should contain allOf( - "builder-string-tag" -> TagValue.String("value"), - "builder-boolean-tag-true" -> TagValue.True, - "builder-boolean-tag-false" -> TagValue.False, - "builder-number-tag" -> TagValue.Number(42), - "span-string-tag" -> TagValue.String("value"), - "span-boolean-tag-true" -> TagValue.True, - "span-boolean-tag-false" -> TagValue.False, - "span-number-tag" -> TagValue.Number(42) - ) - - finishedSpan.annotations.length shouldBe (4) - val annotations = finishedSpan.annotations.groupBy(_.name) - annotations.keys should contain allOf( - "simple-annotation", - "regular-annotation", - "custom-annotation-1", - "custom-annotation-2" - ) - - val customAnnotationOne = annotations("custom-annotation-1").head - customAnnotationOne.timestampMicros shouldBe (4200) - customAnnotationOne.fields shouldBe (Map("custom" -> "yes-1")) - - val customAnnotationTwo = annotations("custom-annotation-2").head - customAnnotationTwo.timestampMicros shouldBe (4201) - customAnnotationTwo.fields shouldBe (Map("custom" -> "yes-2")) - - finishedSpan.context.baggage.getAll() should contain( - "baggage" -> "value" - ) } } - - "allow storing and retrieving baggage items" in { - val span = Kamon.buildSpan("span-with-baggage").start() - span.addBaggage("my-baggage", "value-1") - span.addBaggage("my-baggage", "value-2") - span.addBaggage("my-other-baggage", "value-3") - - span.context().baggage.getAll() should contain only( - "my-baggage" -> "value-2", - "my-other-baggage" -> "value-3" - ) - } } } diff --git a/kamon-core/src/test/scala/kamon/trace/TracerSpec.scala b/kamon-core/src/test/scala/kamon/trace/TracerSpec.scala index 5abfe723..fb5bb313 100644 --- a/kamon-core/src/test/scala/kamon/trace/TracerSpec.scala +++ b/kamon-core/src/test/scala/kamon/trace/TracerSpec.scala @@ -2,10 +2,9 @@ package kamon.trace import com.typesafe.config.ConfigFactory import kamon.Kamon +import kamon.context.Context import kamon.testkit.{SpanBuilding, SpanInspector} import kamon.trace.Span.TagValue -import kamon.trace.SpanContext.Source -import kamon.trace.SpanContextCodec.Format import org.scalatest.{Matchers, OptionValues, WordSpec} class TracerSpec extends WordSpec with Matchers with SpanBuilding with OptionValues { @@ -42,33 +41,16 @@ class TracerSpec extends WordSpec with Matchers with SpanBuilding with OptionVal ("boolean" -> TagValue.True)) } -// "do not interfere with the currently active Span if not requested when starting a Span" in { -// val previouslyActiveSpan = tracer.activeSpan() -// tracer.buildSpan("myOperation").start() -// tracer.activeSpan() should be theSameInstanceAs(previouslyActiveSpan) -// } -// -// "make a span active with started with the .startActive() function and restore the previous Span when deactivated" in { -// val previouslyActiveSpan = tracer.activeSpan() -// val activeSpan = tracer.buildSpan("myOperation").startActive() -// -// tracer.activeSpan() shouldNot be theSameInstanceAs(previouslyActiveSpan) -// val activeSpanData = inspect(activeSpan) -// activeSpanData.operationName() shouldBe "myOperation" -// -// activeSpan.deactivate() -// tracer.activeSpan() should be theSameInstanceAs(previouslyActiveSpan) -// } - "not have any parent Span if there is ActiveSpan and no parent was explicitly given" in { val span = tracer.buildSpan("myOperation").start() val spanData = inspect(span) spanData.context().parentID shouldBe IdentityProvider.NoIdentifier } - "use the currently active span as parent" in { + + "automatically take the Span from the current Context as parent" in { val parent = tracer.buildSpan("myOperation").start() - val child = Kamon.withActiveSpan(parent) { + val child = Kamon.withContext(Context.create(Span.ContextKey, parent)) { tracer.buildSpan("childOperation").asChildOf(parent).start() } @@ -79,7 +61,7 @@ class TracerSpec extends WordSpec with Matchers with SpanBuilding with OptionVal "ignore the currently active span as parent if explicitly requested" in { val parent = tracer.buildSpan("myOperation").start() - val child = Kamon.withActiveSpan(parent) { + val child = Kamon.withContext(Context.create(Span.ContextKey, parent)) { tracer.buildSpan("childOperation").ignoreActiveSpan().start() } @@ -93,53 +75,6 @@ class TracerSpec extends WordSpec with Matchers with SpanBuilding with OptionVal spanData.startTimestamp() shouldBe 100 } - "inject and extract a SpanContext from a TextMap carrier" in { - val spanContext = createSpanContext() - val injected = Kamon.inject(spanContext, Format.TextMap) - val extractedSpanContext = Kamon.extract(Format.TextMap, injected).value - - spanContext.traceID shouldBe(extractedSpanContext.traceID) - spanContext.spanID shouldBe(extractedSpanContext.spanID) - spanContext.parentID shouldBe(extractedSpanContext.parentID) - spanContext.baggage.getAll() shouldBe(extractedSpanContext.baggage.getAll()) - } - - "inject and extract a SpanContext from a TextMap carrier supplied by the caller" in { - val spanContext = createSpanContext() - val carrier = TextMap.Default() - Kamon.inject(spanContext, Format.TextMap, carrier) - val extractedSpanContext = Kamon.extract(Format.TextMap, carrier).value - - spanContext.traceID shouldBe(extractedSpanContext.traceID) - spanContext.spanID shouldBe(extractedSpanContext.spanID) - spanContext.parentID shouldBe(extractedSpanContext.parentID) - spanContext.baggage.getAll() shouldBe(extractedSpanContext.baggage.getAll()) - } - - "inject and extract a SpanContext from a HttpHeaders carrier" in { - val spanContext = createSpanContext() - val injected = Kamon.inject(spanContext, Format.HttpHeaders) - val extractedSpanContext = Kamon.extract(Format.HttpHeaders, injected).value - - spanContext.traceID shouldBe(extractedSpanContext.traceID) - spanContext.spanID shouldBe(extractedSpanContext.spanID) - spanContext.parentID shouldBe(extractedSpanContext.parentID) - spanContext.baggage.getAll() shouldBe(extractedSpanContext.baggage.getAll()) - } - - "inject and extract a SpanContext from a HttpHeaders using a TextMap provided by the caller" in { - val spanContext = createSpanContext() - val carrier = TextMap.Default() - Kamon.inject(spanContext, Format.HttpHeaders, carrier) - val extractedSpanContext = Kamon.extract(Format.HttpHeaders, carrier).value - - spanContext.traceID shouldBe(extractedSpanContext.traceID) - spanContext.spanID shouldBe(extractedSpanContext.spanID) - spanContext.parentID shouldBe(extractedSpanContext.parentID) - spanContext.baggage.getAll() shouldBe(extractedSpanContext.baggage.getAll()) - } - - "preserve the same Span and Parent identifier when creating a Span with a remote parent if join-remote-parents-with-same-span-id is enabled" in { val previousConfig = Kamon.config() @@ -148,12 +83,12 @@ class TracerSpec extends WordSpec with Matchers with SpanBuilding with OptionVal .withFallback(Kamon.config()) } - val remoteParent = createSpanContext().copy(source = Source.Remote) + val remoteParent = Span.Remote(createSpanContext()) val childData = inspect(tracer.buildSpan("local").asChildOf(remoteParent).start()) - childData.context().traceID shouldBe remoteParent.traceID - childData.context().parentID shouldBe remoteParent.parentID - childData.context().spanID shouldBe remoteParent.spanID + childData.context().traceID shouldBe remoteParent.context.traceID + childData.context().parentID shouldBe remoteParent.context.parentID + childData.context().spanID shouldBe remoteParent.context.spanID Kamon.reconfigure(previousConfig) } |