Skip to content

Commit

Permalink
Merge pull request #877 from iRevive/docs/improvements
Browse files Browse the repository at this point in the history
Minor documentation tweaks
  • Loading branch information
iRevive authored Dec 31, 2024
2 parents 6783b22 + 9719d95 commit f2d0850
Showing 1 changed file with 15 additions and 12 deletions.
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

0 comments on commit f2d0850

Please sign in to comment.