swift-distributed-tracing icon indicating copy to clipboard operation
swift-distributed-tracing copied to clipboard

Introduce Propagator protocol

Open slashmo opened this issue 4 years ago • 2 comments

Preface

I noticed that while AWS is Otel-compatible, it does not (yet?) support W3C TraceContext for propagation, which is the default used in Otel. Instead, to support it in my Otel Tracer, I need to add an additional propagator (Injector/Extractor) for AWS X-Ray's TraceID format and an IDGenerator to generate trace ids in X-Ray format.

While implementing this inside OpenTelemetryTracer I first thought about defining a new protocol called OpenTelemetryTraceContextPropagator mirroring Instrument, which requires both inject & extract methods.

protocol OpenTelemetryTraceContextPropagator {
    func extract<Carrier, Extract>(_ carrier: Carrier, into baggage: inout Baggage, using extractor: Extract)
        where Extract: Extractor, Extract.Carrier == Carrier

    func inject<Carrier, Inject>(_ baggage: Baggage, into carrier: inout Carrier, using injector: Inject)
        where Inject: Injector, Inject.Carrier == Carrier
}

Adding a Propagator protocol

As mentioned above, the Propagator protocol I defined mirrored our Instrument protocol exactly. One option would've been to conform my AWSXrayProtopagator to Instrument instead of defining my own type, but that feels somewhat weird as it's not a full-fletched cross-cutting-tool.

This leads me to believe that we might want to introduce a first-class Propagator protocol (that could be "inherited" by the Instrument protocol).


See Also

slashmo avatar Feb 21 '21 12:02 slashmo

I'd like to present another use-case for a Propagator protocol: Jaeger offers an additional mechanism to propagate baggage values, the jaeger-baggage HTTP header. The HotROD example makes use of this for a session and request id.

For our implementation of the Jaeger HotROD example using the Apodini framework, we implemented a JaegerBaggageExtractorInstrument to facility this functionality with swift-distributed-tracing. Same as with the AwsXrayPropagator, it is not a fully fledged Instrument and would benefit from the specificity a first-class Propagator protocol provides.

moritzsternemann avatar Jul 08 '22 11:07 moritzsternemann

I think this could be done post 1.0 🤔

ktoso avatar Feb 24 '23 10:02 ktoso