From 2f05b3b4823f98a94de5c4b49fb5efeb0f2b0e2d Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Thu, 5 Apr 2018 21:20:34 +0200 Subject: do not encode ParentID on B3 headers if not present, fixes kamon-io/kamon-akka-http#35 --- .../test/scala/kamon/trace/B3SpanCodecSpec.scala | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'kamon-core-tests') diff --git a/kamon-core-tests/src/test/scala/kamon/trace/B3SpanCodecSpec.scala b/kamon-core-tests/src/test/scala/kamon/trace/B3SpanCodecSpec.scala index e6fa283e..f718d806 100644 --- a/kamon-core-tests/src/test/scala/kamon/trace/B3SpanCodecSpec.scala +++ b/kamon-core-tests/src/test/scala/kamon/trace/B3SpanCodecSpec.scala @@ -28,15 +28,21 @@ class B3SpanCodecSpec extends WordSpecLike with Matchers with OptionValues with "The ExtendedB3 SpanContextCodec" should { "return a TextMap containing the SpanContext data" in { - val context = testContext() - - val textMap = extendedB3Codec.encode(context) + val textMap = extendedB3Codec.encode(testContext()) 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" } + "do not include the X-B3-ParentSpanId if there is no parent" in { + val textMap = extendedB3Codec.encode(testContextWithoutParent()) + textMap.get("X-B3-TraceId").value shouldBe "1234" + textMap.get("X-B3-ParentSpanId") shouldBe empty + textMap.get("X-B3-SpanId").value shouldBe "4321" + textMap.get("X-B3-Sampled").value shouldBe "1" + } + "not inject anything if there is no Span in the Context" in { val textMap = extendedB3Codec.encode(Context.Empty) @@ -189,4 +195,14 @@ class B3SpanCodecSpec extends WordSpecLike with Matchers with OptionValues with Context.create().withKey(Span.ContextKey, Span.Remote(spanContext)) } + def testContextWithoutParent(): Context = { + val spanContext = createSpanContext().copy( + traceID = Identifier("1234", Array[Byte](1, 2, 3, 4)), + spanID = Identifier("4321", Array[Byte](4, 3, 2, 1)), + parentID = IdentityProvider.NoIdentifier + ) + + Context.create().withKey(Span.ContextKey, Span.Remote(spanContext)) + } + } \ No newline at end of file -- cgit v1.2.3