Skip to content

Commit

Permalink
Simplify to TextMapUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
rossabaker committed Apr 27, 2023
1 parent bb34c18 commit 4568b85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 4568b85

Please sign in to comment.