From 9f8537dfbff554c11819c030d859f87fe2bda29f Mon Sep 17 00:00:00 2001 From: Maksym Ochenashko Date: Mon, 29 Jan 2024 13:23:53 +0200 Subject: [PATCH] sdk-trace: move `W3CTraceContextPropagator` to the `context.propagation` package --- .../W3CTraceContextPropagator.scala | 44 ++++++++++++------- .../otel4s/sdk/trace/SdkTracerSuite.scala | 4 +- .../W3CTraceContextPropagatorSuite.scala | 4 +- 3 files changed, 33 insertions(+), 19 deletions(-) rename sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/{ => context}/propagation/W3CTraceContextPropagator.scala (91%) rename sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/{ => context}/propagation/W3CTraceContextPropagatorSuite.scala (97%) diff --git a/sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/propagation/W3CTraceContextPropagator.scala b/sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/context/propagation/W3CTraceContextPropagator.scala similarity index 91% rename from sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/propagation/W3CTraceContextPropagator.scala rename to sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/context/propagation/W3CTraceContextPropagator.scala index 1800149b1..1aafefe70 100644 --- a/sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/propagation/W3CTraceContextPropagator.scala +++ b/sdk/trace/src/main/scala/org/typelevel/otel4s/sdk/trace/context/propagation/W3CTraceContextPropagator.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.typelevel.otel4s.sdk.trace.propagation +package org.typelevel.otel4s.sdk.trace.context.propagation import cats.syntax.apply._ import org.typelevel.otel4s.context.propagation.TextMapGetter @@ -33,21 +33,11 @@ import org.typelevel.otel4s.trace.TraceState * @see * [[https://www.w3.org/TR/trace-context/]] */ -object W3CTraceContextPropagator extends TextMapPropagator[Context] { +private final class W3CTraceContextPropagator + extends TextMapPropagator[Context] { - private object Headers { - val TraceParent = "traceparent" - val TraceState = "tracestate" - } - - private object Const { - val Delimiter = "-" - val Version = "00" - val TraceStateEntryPattern = "[ \t]*,[ \t]*".r - val TraceStateEntryDelimiter = "," - val TraceStateKeyValueDelimiter = "=" - val TraceStateMaxMembers = 32 - } + import W3CTraceContextPropagator.Headers + import W3CTraceContextPropagator.Const val fields: List[String] = List(Headers.TraceParent, Headers.TraceState) @@ -145,3 +135,27 @@ object W3CTraceContextPropagator extends TextMapPropagator[Context] { override def toString: String = "W3CTraceContextPropagator" } + +object W3CTraceContextPropagator { + + private val Default = new W3CTraceContextPropagator + + private object Headers { + val TraceParent = "traceparent" + val TraceState = "tracestate" + } + + private object Const { + val Delimiter = "-" + val Version = "00" + val TraceStateEntryPattern = "[ \t]*,[ \t]*".r + val TraceStateEntryDelimiter = "," + val TraceStateKeyValueDelimiter = "=" + val TraceStateMaxMembers = 32 + } + + /** Returns an instance of the W3CTraceContextPropagator. + */ + def default: TextMapPropagator[Context] = Default + +} diff --git a/sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/SdkTracerSuite.scala b/sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/SdkTracerSuite.scala index 035fb4987..b25ef5959 100644 --- a/sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/SdkTracerSuite.scala +++ b/sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/SdkTracerSuite.scala @@ -34,13 +34,13 @@ import org.typelevel.otel4s.context.propagation.PassThroughPropagator import org.typelevel.otel4s.context.propagation.TextMapPropagator import org.typelevel.otel4s.sdk.common.InstrumentationScope import org.typelevel.otel4s.sdk.context.Context +import org.typelevel.otel4s.sdk.trace.context.propagation.W3CTraceContextPropagator import org.typelevel.otel4s.sdk.trace.data.EventData import org.typelevel.otel4s.sdk.trace.data.SpanData import org.typelevel.otel4s.sdk.trace.data.StatusData import org.typelevel.otel4s.sdk.trace.exporter.InMemorySpanExporter import org.typelevel.otel4s.sdk.trace.processor.BatchSpanProcessor import org.typelevel.otel4s.sdk.trace.processor.SpanProcessor -import org.typelevel.otel4s.sdk.trace.propagation.W3CTraceContextPropagator import org.typelevel.otel4s.sdk.trace.samplers.Sampler import org.typelevel.otel4s.trace.Span import org.typelevel.otel4s.trace.Status @@ -962,7 +962,7 @@ class SdkTracerSuite extends CatsEffectSuite { import org.typelevel.otel4s.instances.local._ val textMapPropagators: List[TextMapPropagator[Context]] = - List(W3CTraceContextPropagator) ++ additionalPropagators + W3CTraceContextPropagator.default :: additionalPropagators def createTracerProvider( processor: SpanProcessor[IO] diff --git a/sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/propagation/W3CTraceContextPropagatorSuite.scala b/sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/context/propagation/W3CTraceContextPropagatorSuite.scala similarity index 97% rename from sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/propagation/W3CTraceContextPropagatorSuite.scala rename to sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/context/propagation/W3CTraceContextPropagatorSuite.scala index 7e150e1c7..95076189f 100644 --- a/sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/propagation/W3CTraceContextPropagatorSuite.scala +++ b/sdk/trace/src/test/scala/org/typelevel/otel4s/sdk/trace/context/propagation/W3CTraceContextPropagatorSuite.scala @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.typelevel.otel4s.sdk.trace.propagation +package org.typelevel.otel4s.sdk.trace.context.propagation import munit._ import org.scalacheck.Prop @@ -26,7 +26,7 @@ import org.typelevel.otel4s.trace.TraceState class W3CTraceContextPropagatorSuite extends ScalaCheckSuite { - private val propagator = W3CTraceContextPropagator + private val propagator = W3CTraceContextPropagator.default // // Common