From 06b51d38550bbae6a492b380b0759a90ebdc3c52 Mon Sep 17 00:00:00 2001 From: Marissa Date: Mon, 29 Jan 2024 14:52:31 -0500 Subject: [PATCH] Expose `OtelJava`'s `LocalContext` --- .../org/typelevel/otel4s/oteljava/OtelJava.scala | 13 ++++++++----- .../typelevel/otel4s/oteljava/OtelJavaSuite.scala | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/oteljava/all/src/main/scala/org/typelevel/otel4s/oteljava/OtelJava.scala b/oteljava/all/src/main/scala/org/typelevel/otel4s/oteljava/OtelJava.scala index 39b57d98c..8cac050b7 100644 --- a/oteljava/all/src/main/scala/org/typelevel/otel4s/oteljava/OtelJava.scala +++ b/oteljava/all/src/main/scala/org/typelevel/otel4s/oteljava/OtelJava.scala @@ -43,12 +43,16 @@ import org.typelevel.otel4s.oteljava.metrics.Metrics import org.typelevel.otel4s.oteljava.trace.Traces import org.typelevel.otel4s.trace.TracerProvider -sealed class OtelJava[F[_]] private ( +final class OtelJava[F[_]] private ( + jOtel: JOpenTelemetry, val propagators: ContextPropagators[Context], val meterProvider: MeterProvider[F], val tracerProvider: TracerProvider[F], -) extends Otel4s[F] { +)(implicit val localContext: LocalContext[F]) + extends Otel4s[F] { type Ctx = Context + + override def toString: String = s"OtelJava{$jOtel}" } object OtelJava { @@ -78,12 +82,11 @@ object OtelJava { val metrics = Metrics.forAsync(jOtel) val traces = Traces.local(jOtel, contextPropagators) new OtelJava[F]( + jOtel, contextPropagators, metrics.meterProvider, traces.tracerProvider, - ) { - override def toString: String = jOtel.toString - } + ) } /** Lifts the acquisition of a Java OpenTelemetrySdk instance to a Resource. diff --git a/oteljava/all/src/test/scala/org/typelevel/otel4s/oteljava/OtelJavaSuite.scala b/oteljava/all/src/test/scala/org/typelevel/otel4s/oteljava/OtelJavaSuite.scala index 4b78d05f7..667eea93f 100644 --- a/oteljava/all/src/test/scala/org/typelevel/otel4s/oteljava/OtelJavaSuite.scala +++ b/oteljava/all/src/test/scala/org/typelevel/otel4s/oteljava/OtelJavaSuite.scala @@ -28,7 +28,7 @@ class OtelJavaSuite extends CatsEffectSuite { .forAsync[IO](testSdk) .map(testOtel4s => { val res = testOtel4s.toString() - assert(clue(res).startsWith("OpenTelemetrySdk")) + assert(clue(res).contains("OpenTelemetrySdk")) }) } }