diff --git a/core/common/src/main/scala/org/typelevel/otel4s/TextMapPropagator.scala b/core/common/src/main/scala/org/typelevel/otel4s/TextMapPropagator.scala index 0113bc782..cd9ef1268 100644 --- a/core/common/src/main/scala/org/typelevel/otel4s/TextMapPropagator.scala +++ b/core/common/src/main/scala/org/typelevel/otel4s/TextMapPropagator.scala @@ -85,7 +85,7 @@ trait TextMapPropagator[F[_]] { * @return * a copy of the carrier, with new fields injected */ - def injected[A: TextMapInjector](ctx: Vault, carrier: A): A + def injected[A: TextMapUpdater](ctx: Vault, carrier: A): A } object TextMapPropagator { @@ -100,7 +100,7 @@ object TextMapPropagator { def inject[A: TextMapSetter](ctx: Vault, carrier: A): F[Unit] = Applicative[F].unit - def injected[A: TextMapInjector](ctx: Vault, carrier: A): A = + def injected[A: TextMapUpdater](ctx: Vault, carrier: A): A = carrier } } diff --git a/core/common/src/main/scala/org/typelevel/otel4s/TextMapInjector.scala b/core/common/src/main/scala/org/typelevel/otel4s/TextMapUpdater.scala similarity index 79% rename from core/common/src/main/scala/org/typelevel/otel4s/TextMapInjector.scala rename to core/common/src/main/scala/org/typelevel/otel4s/TextMapUpdater.scala index 126a85914..2a41f88d7 100644 --- a/core/common/src/main/scala/org/typelevel/otel4s/TextMapInjector.scala +++ b/core/common/src/main/scala/org/typelevel/otel4s/TextMapUpdater.scala @@ -16,12 +16,6 @@ package org.typelevel.otel4s -trait TextMapInjector[A] { - type Builder - - def textMapSetter: TextMapSetter[Builder] - - def toBuilder(carrier: A): Builder - - def toCarrier(builder: Builder): A +trait TextMapUpdater[A] { + def updated(carrier: A, key: String, value: String): A } diff --git a/java/common/src/main/scala/org/typelevel/otel4s/java/TextMapPropagatorImpl.scala b/java/common/src/main/scala/org/typelevel/otel4s/java/TextMapPropagatorImpl.scala index afc5b6026..270f0490a 100644 --- a/java/common/src/main/scala/org/typelevel/otel4s/java/TextMapPropagatorImpl.scala +++ b/java/common/src/main/scala/org/typelevel/otel4s/java/TextMapPropagatorImpl.scala @@ -41,14 +41,16 @@ private[java] class TextMapPropagatorImpl[F[_]: Sync]( ) def injected[A](ctx: Vault, carrier: A)(implicit - injector: TextMapInjector[A] + injector: TextMapUpdater[A] ): A = { - val builder = injector.toBuilder(carrier) - jPropagator.inject( + var injectedCarrier = carrier + jPropagator.inject[Null]( toJContext(ctx), - builder, - fromTextMapSetter(injector.textMapSetter) + null, // explicitly allowed per opentelemetry-java, so our setter can be a lambda! + (_, key, value) => { + injectedCarrier = injector.updated(injectedCarrier, key, value) + } ) - injector.toCarrier(builder) + injectedCarrier } }