From 313b7e7dac497c9563c09d7c8a47af8353e3e6c9 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Tue, 30 Oct 2018 17:24:54 +0100 Subject: include trace identifiers in HTTP responses, fixes #558 --- kamon-core-tests/src/test/resources/reference.conf | 10 ++++++++-- .../instrumentation/HttpServerInstrumentationSpec.scala | 12 ++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'kamon-core-tests') diff --git a/kamon-core-tests/src/test/resources/reference.conf b/kamon-core-tests/src/test/resources/reference.conf index c092af08..60852722 100644 --- a/kamon-core-tests/src/test/resources/reference.conf +++ b/kamon-core-tests/src/test/resources/reference.conf @@ -21,8 +21,14 @@ kamon { instrumentation { http-server { default { - tracing.preferred-trace-id-tag = "correlation-id" - tracing.tags.from-context.peer = span + tracing { + preferred-trace-id-tag = "correlation-id" + tags.from-context.peer = span + response-headers { + trace-id = "x-trace-id" + span-id = "x-span-id" + } + } } no-span-metrics { diff --git a/kamon-core-tests/src/test/scala/kamon/instrumentation/HttpServerInstrumentationSpec.scala b/kamon-core-tests/src/test/scala/kamon/instrumentation/HttpServerInstrumentationSpec.scala index c3c5f131..62eae45b 100644 --- a/kamon-core-tests/src/test/scala/kamon/instrumentation/HttpServerInstrumentationSpec.scala +++ b/kamon-core-tests/src/test/scala/kamon/instrumentation/HttpServerInstrumentationSpec.scala @@ -220,6 +220,18 @@ class HttpServerInstrumentationSpec extends WordSpec with Matchers with SpanInsp val span = inspect(handler.span) span.tag("peer").value shouldBe "superservice" } + + "write trace identifiers on the responses" in { + val handler = httpServer().receive(fakeRequest("http://localhost:8080/", "/", "GET", Map( + "x-correlation-id" -> "0011223344556677" + ))) + + val responseHeaders = mutable.Map.empty[String, String] + handler.send(fakeResponse(200, responseHeaders), handler.context) + + responseHeaders.get("x-trace-id").value shouldBe "0011223344556677" + responseHeaders.get("x-span-id") shouldBe defined + } } "all capabilities are disabled" should { -- cgit v1.2.3