diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2018-04-05 21:20:34 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2018-04-05 21:33:15 +0200 |
commit | 2f05b3b4823f98a94de5c4b49fb5efeb0f2b0e2d (patch) | |
tree | b09a7ae7cb2159c285fbd0a89cb9096a7f8e03fc /kamon-core-tests/src/test/scala/kamon/trace/B3SpanCodecSpec.scala | |
parent | e711bb0170f0939f9054cea76da0ce09005ccef3 (diff) | |
download | Kamon-2f05b3b4823f98a94de5c4b49fb5efeb0f2b0e2d.tar.gz Kamon-2f05b3b4823f98a94de5c4b49fb5efeb0f2b0e2d.tar.bz2 Kamon-2f05b3b4823f98a94de5c4b49fb5efeb0f2b0e2d.zip |
do not encode ParentID on B3 headers if not present, fixes kamon-io/kamon-akka-http#35
Diffstat (limited to 'kamon-core-tests/src/test/scala/kamon/trace/B3SpanCodecSpec.scala')
-rw-r--r-- | kamon-core-tests/src/test/scala/kamon/trace/B3SpanCodecSpec.scala | 22 |
1 files changed, 19 insertions, 3 deletions
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 |