-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Baggage #431
Comments
I tried to find some easy workaround, but I failed to do so. The only one I could come up with is to manipulate the underlying context but that would be problematic as I don't know how to get easily the Can you help me how to manipulate the context more easily? Why is the Context hidden in |
Also let me note "Tracing - interop with Java-instrumented libraries" mentions these imports:
None of them exists in 0.4.0. |
Hello @fugafree.
The site is built from the most recent main branch, and these changes have not been released yet. In the import org.typelevel.otel4s.java.instances._ // brings Local derived from IOLocal
import org.typelevel.otel4s.java.OtelJava Here is an example of how to run an effect with custom baggage. //> using scala 2
//> using toolkit typelevel:latest
//> using lib org.typelevel::otel4s-java:0.4.0
//> using lib "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.34.1"
import cats.effect._
import cats.mtl.syntax.local._
import io.opentelemetry.api.GlobalOpenTelemetry
import io.opentelemetry.api.baggage.Baggage
import org.typelevel.otel4s.java.OtelJava
import org.typelevel.otel4s.java.context.Context
import org.typelevel.otel4s.java.instances._ // bring Local for IOLocal
object BaggageExample extends IOApp.Simple {
def run: IO[Unit] = {
IOLocal(Context.root).flatMap { implicit ioLocal: IOLocal[Context] =>
val otel = OtelJava.local[IO](GlobalOpenTelemetry.get)
otel.tracerProvider.get("tracer").flatMap { implicit tracer =>
val baggage = Baggage.builder().put("key", "value").build()
tracer.span("my-span")
.use(span => IO.println("my span: " + span))
.local[Context](ctx => Context.wrap(ctx.underlying.`with`(baggage))) // add the baggage
}
}
}
} |
We may expose utility methods eventually. Currently, I'm actively working on the Scala implementation of the tracing SDK module. Once we have it in place, we can make a proper decision on how to extend the API to make sure both implementations support it. |
I opine that |
Hello @iRevive, thank you for the answers, and that you already started to work on it. In the mentioned pull request you summarised the challenge pretty good. |
see #464 for exposing it from |
Related: #452, adds Baggage to sdk-common |
With the upcoming release you can inject the baggage in the following way: val otel4s: OtelJava[F] = ???
val program: F[Unit] = ???
val baggage = Baggage.builder().put("key", "value").build()
otel4s.localContext.local(program)(ctx => Context.wrap(ctx.underlying.`with`(baggage))) |
Thank you! Much more easier now. Sadly the Baggage Java API is still a mess, and modifying a value is still a paint, but at least doable. |
In some sense, it's done, so we can close it off 🙂 |
Exposing the underlying Java context via local is indeed done, but I would rather call that a workaround than a solution.
Since next to |
It would be nice to have baggage support in the library for getting and setting baggage on the context.
In Java there is a baggage builder and the baggage can be set on the context (
jContext.`with`(Baggage.builder().build())
)The text was updated successfully, but these errors were encountered: