Skip to content

Commit

Permalink
Merge pull request #461 from iRevive/sdk-trace/move-w3c
Browse files Browse the repository at this point in the history
sdk-trace: move `W3CTraceContextPropagator` to the `context.propagation` package
  • Loading branch information
iRevive authored Jan 29, 2024
2 parents f25fd20 + 9f8537d commit f720814
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +26,7 @@ import org.typelevel.otel4s.trace.TraceState

class W3CTraceContextPropagatorSuite extends ScalaCheckSuite {

private val propagator = W3CTraceContextPropagator
private val propagator = W3CTraceContextPropagator.default

//
// Common
Expand Down

0 comments on commit f720814

Please sign in to comment.