diff --git a/modules/0.22/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala b/modules/0.22/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala index 48c2fbe..427585f 100644 --- a/modules/0.22/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala +++ b/modules/0.22/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala @@ -28,26 +28,34 @@ import org.http4s.client.Client object KamonSupport { - private var _instrumentation = instrumentation(Kamon.config()) + private val defaultComponentName = "http4s.client" + private var _instrumentation = + instrumentation(Kamon.config(), defaultComponentName) private def instrumentation( - kamonConfig: Config + kamonConfig: Config, + componentName: String = "http4s.client" ): HttpClientInstrumentation = { val httpClientConfig = kamonConfig.getConfig("kamon.instrumentation.http4s.client") - HttpClientInstrumentation.from(httpClientConfig, "http4s.client") + HttpClientInstrumentation.from(httpClientConfig, componentName) } - Kamon.onReconfigure(newConfig => - _instrumentation = instrumentation(newConfig) - ) - def apply[F[_]](underlying: Client[F])(implicit F: Sync[F]): Client[F] = + this(underlying, defaultComponentName) + + def apply[F[_]](underlying: Client[F], componentName: String)(implicit + F: Sync[F] + ): Client[F] = { + Kamon.onReconfigure(newConfig => + _instrumentation = instrumentation(newConfig, componentName) + ) Client { request => // this needs to run on the same thread as the caller, so can't be suspended in F val ctx = Kamon.currentContext() kamonClient(underlying)(request)(ctx)(_instrumentation) } + } private def kamonClient[F[_]]( underlying: Client[F] diff --git a/modules/0.22/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala b/modules/0.22/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala index d0716d7..70ba33e 100644 --- a/modules/0.22/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala +++ b/modules/0.22/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala @@ -51,7 +51,10 @@ class ClientInstrumentationSpec } val client: Client[IO] = - KamonSupport[IO](Client.fromHttpApp[IO](service.orNotFound)) + KamonSupport[IO]( + Client.fromHttpApp[IO](service.orNotFound), + "my-service-name" + ) "The Client instrumentation" should { "propagate the current context and generate a span inside an action and complete the ws request" in { @@ -66,7 +69,7 @@ class ClientInstrumentationSpec span.operationName shouldBe "/tracing/ok" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.metricTags.get(plainLong("http.status_code")) shouldBe 200 span.metricTags.get( @@ -99,7 +102,7 @@ class ClientInstrumentationSpec val span = testSpanReporter().nextSpan().value span.operationName shouldBe "/tracing/ok" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.hasError shouldBe true @@ -122,7 +125,7 @@ class ClientInstrumentationSpec val span = testSpanReporter().nextSpan().value span.operationName shouldBe "/tracing/not-found" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.metricTags.get(plainLong("http.status_code")) shouldBe 404 span.metricTags.get( @@ -149,7 +152,7 @@ class ClientInstrumentationSpec span.operationName shouldBe "/tracing/error" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.hasError shouldBe true span.metricTags.get(plainLong("http.status_code")) shouldBe 500 diff --git a/modules/0.23/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala b/modules/0.23/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala index 48c2fbe..427585f 100644 --- a/modules/0.23/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala +++ b/modules/0.23/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala @@ -28,26 +28,34 @@ import org.http4s.client.Client object KamonSupport { - private var _instrumentation = instrumentation(Kamon.config()) + private val defaultComponentName = "http4s.client" + private var _instrumentation = + instrumentation(Kamon.config(), defaultComponentName) private def instrumentation( - kamonConfig: Config + kamonConfig: Config, + componentName: String = "http4s.client" ): HttpClientInstrumentation = { val httpClientConfig = kamonConfig.getConfig("kamon.instrumentation.http4s.client") - HttpClientInstrumentation.from(httpClientConfig, "http4s.client") + HttpClientInstrumentation.from(httpClientConfig, componentName) } - Kamon.onReconfigure(newConfig => - _instrumentation = instrumentation(newConfig) - ) - def apply[F[_]](underlying: Client[F])(implicit F: Sync[F]): Client[F] = + this(underlying, defaultComponentName) + + def apply[F[_]](underlying: Client[F], componentName: String)(implicit + F: Sync[F] + ): Client[F] = { + Kamon.onReconfigure(newConfig => + _instrumentation = instrumentation(newConfig, componentName) + ) Client { request => // this needs to run on the same thread as the caller, so can't be suspended in F val ctx = Kamon.currentContext() kamonClient(underlying)(request)(ctx)(_instrumentation) } + } private def kamonClient[F[_]]( underlying: Client[F] diff --git a/modules/0.23/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala b/modules/0.23/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala index 0efa625..1648f2f 100644 --- a/modules/0.23/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala +++ b/modules/0.23/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala @@ -52,7 +52,10 @@ class ClientInstrumentationSpec } val client: Client[IO] = - KamonSupport[IO](Client.fromHttpApp[IO](service.orNotFound)) + KamonSupport[IO]( + Client.fromHttpApp[IO](service.orNotFound), + "my-service-name" + ) "The Client instrumentation" should { "propagate the current context and generate a span inside an action and complete the ws request" in { @@ -67,7 +70,7 @@ class ClientInstrumentationSpec span.operationName shouldBe "/tracing/ok" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.metricTags.get(plainLong("http.status_code")) shouldBe 200 span.metricTags.get( @@ -100,7 +103,7 @@ class ClientInstrumentationSpec val span = testSpanReporter().nextSpan().value span.operationName shouldBe "/tracing/ok" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.hasError shouldBe true @@ -123,7 +126,7 @@ class ClientInstrumentationSpec val span = testSpanReporter().nextSpan().value span.operationName shouldBe "/tracing/not-found" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.metricTags.get(plainLong("http.status_code")) shouldBe 404 span.metricTags.get( @@ -150,7 +153,7 @@ class ClientInstrumentationSpec span.operationName shouldBe "/tracing/error" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.hasError shouldBe true span.metricTags.get(plainLong("http.status_code")) shouldBe 500 diff --git a/modules/1.0/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala b/modules/1.0/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala index 48c2fbe..427585f 100644 --- a/modules/1.0/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala +++ b/modules/1.0/src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala @@ -28,26 +28,34 @@ import org.http4s.client.Client object KamonSupport { - private var _instrumentation = instrumentation(Kamon.config()) + private val defaultComponentName = "http4s.client" + private var _instrumentation = + instrumentation(Kamon.config(), defaultComponentName) private def instrumentation( - kamonConfig: Config + kamonConfig: Config, + componentName: String = "http4s.client" ): HttpClientInstrumentation = { val httpClientConfig = kamonConfig.getConfig("kamon.instrumentation.http4s.client") - HttpClientInstrumentation.from(httpClientConfig, "http4s.client") + HttpClientInstrumentation.from(httpClientConfig, componentName) } - Kamon.onReconfigure(newConfig => - _instrumentation = instrumentation(newConfig) - ) - def apply[F[_]](underlying: Client[F])(implicit F: Sync[F]): Client[F] = + this(underlying, defaultComponentName) + + def apply[F[_]](underlying: Client[F], componentName: String)(implicit + F: Sync[F] + ): Client[F] = { + Kamon.onReconfigure(newConfig => + _instrumentation = instrumentation(newConfig, componentName) + ) Client { request => // this needs to run on the same thread as the caller, so can't be suspended in F val ctx = Kamon.currentContext() kamonClient(underlying)(request)(ctx)(_instrumentation) } + } private def kamonClient[F[_]]( underlying: Client[F] diff --git a/modules/1.0/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala b/modules/1.0/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala index 0efa625..1648f2f 100644 --- a/modules/1.0/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala +++ b/modules/1.0/src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala @@ -52,7 +52,10 @@ class ClientInstrumentationSpec } val client: Client[IO] = - KamonSupport[IO](Client.fromHttpApp[IO](service.orNotFound)) + KamonSupport[IO]( + Client.fromHttpApp[IO](service.orNotFound), + "my-service-name" + ) "The Client instrumentation" should { "propagate the current context and generate a span inside an action and complete the ws request" in { @@ -67,7 +70,7 @@ class ClientInstrumentationSpec span.operationName shouldBe "/tracing/ok" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.metricTags.get(plainLong("http.status_code")) shouldBe 200 span.metricTags.get( @@ -100,7 +103,7 @@ class ClientInstrumentationSpec val span = testSpanReporter().nextSpan().value span.operationName shouldBe "/tracing/ok" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.hasError shouldBe true @@ -123,7 +126,7 @@ class ClientInstrumentationSpec val span = testSpanReporter().nextSpan().value span.operationName shouldBe "/tracing/not-found" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.metricTags.get(plainLong("http.status_code")) shouldBe 404 span.metricTags.get( @@ -150,7 +153,7 @@ class ClientInstrumentationSpec span.operationName shouldBe "/tracing/error" span.kind shouldBe Span.Kind.Client - span.metricTags.get(plain("component")) shouldBe "http4s.client" + span.metricTags.get(plain("component")) shouldBe "my-service-name" span.metricTags.get(plain("http.method")) shouldBe "GET" span.hasError shouldBe true span.metricTags.get(plainLong("http.status_code")) shouldBe 500