Skip to content

Commit

Permalink
fixup! Add BaggageManager utility
Browse files Browse the repository at this point in the history
Local#reader
  • Loading branch information
NthPortal committed Feb 4, 2025
1 parent c5dba2e commit 3a13fb2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ trait BaggageManager[F[_]] extends Local[F, Baggage] {
* mapping for the key
*/
def get(key: String): F[Option[Baggage.Entry]] =
applicative.map(ask[Baggage])(_.get(key))
reader(_.get(key))

/** @return
* the value (without [[Baggage.Metadata metadata]]) to which the specified key is mapped, or `None` if the current
* `Baggage` contains no mapping for the key
*/
def getValue(key: String): F[Option[String]] =
applicative.map(ask[Baggage])(_.get(key).map(_.value))
reader(_.get(key).map(_.value))
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private final class BaggageManagerImpl[F[_]] private (implicit localContext: Loc
extends BaggageManager[F] {
def applicative: Applicative[F] = localContext.applicative
def ask[E2 >: Baggage]: F[E2] =
applicative.map(localContext.ask[Context]) { ctx =>
localContext.reader { ctx =>
Option(JBaggage.fromContextOrNull(ctx.underlying))
.fold(Baggage.empty)(_.toScala)
}
Expand All @@ -40,12 +40,12 @@ private final class BaggageManagerImpl[F[_]] private (implicit localContext: Loc
Context.wrap(jCtx.`with`(updated))
}
override def get(key: String): F[Option[Baggage.Entry]] =
applicative.map(localContext.ask[Context]) { ctx =>
localContext.reader { ctx =>
Option(JBaggage.fromContext(ctx.underlying).getEntry(key))
.map(_.toScala)
}
override def getValue(key: String): F[Option[String]] =
applicative.map(localContext.ask[Context]) { ctx =>
localContext.reader { ctx =>
Option(JBaggage.fromContext(ctx.underlying).getEntryValue(key))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private final class SdkBaggageManager[F[_]](implicit localContext: LocalContext[

def applicative: Applicative[F] = localContext.applicative
def ask[E2 >: Baggage]: F[E2] =
applicative.map(localContext.ask[Context])(baggageFromContext)
localContext.reader(baggageFromContext)
def local[A](fa: F[A])(f: Baggage => Baggage): F[A] =
localContext.local(fa) { ctx =>
ctx.updated(BaggageKey, f(baggageFromContext(ctx)))
Expand Down

0 comments on commit 3a13fb2

Please sign in to comment.