Skip to content
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

Minor documentation tweaks #877

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions docs/oteljava/tracing-context-propagation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,31 @@ Add directives to the `*.scala` file:
You need to use `IOLocalContextStorage.localProvider[IO]` to provide the global context storage, backed by `IOLocal`:
```scala mdoc:silent
import cats.effect.IO
import cats.effect.IOApp
import io.opentelemetry.api.trace.{Span => JSpan}
import org.typelevel.otel4s.context.LocalProvider
import org.typelevel.otel4s.oteljava.IOLocalContextStorage
import org.typelevel.otel4s.oteljava.OtelJava
import org.typelevel.otel4s.oteljava.context.Context
import org.typelevel.otel4s.trace.Tracer

def program(tracer: Tracer[IO]): IO[Unit] =
tracer.span("test").use { span => // start 'test' span using otel4s
println(s"jctx : ${JSpan.current().getSpanContext}") // get a span from a ThreadLocal var
IO.println(s"otel4s: ${span.context}")
}
object Main extends IOApp.Simple {
def program(tracer: Tracer[IO]): IO[Unit] =
tracer.span("test").use { span => // start 'test' span using otel4s
println(s"jctx: ${JSpan.current().getSpanContext}") // get a span from a ThreadLocal var
IO.println(s"otel4s: ${span.context}")
}

def run: IO[Unit] = {
implicit val provider: LocalProvider[IO, Context] =
IOLocalContextStorage.localProvider[IO]
def run: IO[Unit] = {
implicit val provider: LocalProvider[IO, Context] =
IOLocalContextStorage.localProvider[IO]

OtelJava.autoConfigured[IO]().use { otelJava =>
otelJava.tracerProvider.tracer("com.service").get.flatMap { tracer =>
program(tracer)
OtelJava.autoConfigured[IO]().use { otelJava =>
otelJava.tracerProvider.tracer("com.service").get.flatMap { tracer =>
program(tracer)
}
}
}
}
}
```

Expand Down