#OpenTelemetry Propagation API

    This package moves trace context and baggage through text-based carriers such as HTTP headers.

    #Carrier traits

    • Injector: write side of an outbound carrier
    • Extractor: read side of an inbound carrier

    Map[String, String] implements both traits. When used through Injector, keys are normalized to lowercase. When used through Extractor, lookups are case-insensitive, which makes the map convenient for HTTP-style headers.

    #TextMapPropagator

    • TextMapPropagator::from_functions(inject, extract, fields): builds a custom propagator from three callbacks
    • inject_context(context, injector): writes propagation fields into the carrier
    • extract_with_context(context, extractor): reads from the carrier and returns an updated context
    • fields(): reports the header names the propagator may touch

    #BaggagePropagator

    • BaggagePropagator::new(): reads and writes the baggage header
    • inject_context(context, injector): serializes baggage into the carrier
    • extract_with_context(context, extractor): parses baggage and merges it into the supplied context; extracted entries overwrite existing baggage entries with the same key
    • into_text_map(): erases the concrete type into TextMapPropagator

    Malformed baggage items are ignored. Valid items still survive extraction.

    #TraceContextPropagator

    • TraceContextPropagator::new(): reads and writes traceparent and tracestate
    • inject_context(context, injector): writes the current valid span context
    • extract_with_context(context, extractor): validates the headers and, on success, returns a context with a remote span context attached
    • into_text_map(): erases the concrete type into TextMapPropagator

    Invalid headers are ignored and leave the input context unchanged.

    #TextMapCompositePropagator

    • TextMapCompositePropagator::new(propagators): creates a propagator that runs multiple propagators in order
    • inject_context(context, injector): runs every child propagator
    • extract_with_context(context, extractor): threads the context through the propagators from left to right
    • into_text_map(): erases the concrete type into TextMapPropagator

    Field names are de-duplicated when fields() is queried on the composite.

    Extractor

    pub(open) trait Extractor {
    fn get(Self, StringView) -> String?
    fn keys(Self) -> Array[String] = _
    }

    Read side of a text-map carrier used for inbound propagation.

    Implement this for HTTP header maps or other text carriers that need incoming trace context and baggage extraction. keys() is optional but lets propagators handle case-insensitive carriers more efficiently. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#extract

    Injector

    pub(open) trait Injector {
    fn set(Self, String, String) -> Unit
    }

    Write side of a text-map carrier used for outbound propagation.

    Implement this for HTTP header maps or other text carriers that need outgoing trace context and baggage injection. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#inject

    BaggagePropagator

    pub struct BaggagePropagator {
    inner : TextMapPropagator
    }

    W3C baggage propagator wrapper.

    Reads and writes the baggage header. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#propagation

    BaggagePropagator::extract_with_context

    Extracts baggage from the carrier and returns an updated context. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-extract

    BaggagePropagator::inject_context

    Injects baggage from context into the carrier. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-inject

    BaggagePropagator::into_text_map

    Erases the concrete baggage propagator type into TextMapPropagator. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#propagation

    BaggagePropagator::new

    Creates a baggage propagator that reads and writes the baggage header.

    Extraction is forgiving: malformed entries are ignored and valid entries are merged into the provided context. Spec: https://opentelemetry.io/docs/specs/otel/baggage/api/#propagation

    TextMapCompositePropagator

    pub struct TextMapCompositePropagator {
    inner : TextMapPropagator
    }

    Composite propagator that applies multiple propagators in sequence.

    The default global propagator uses this to combine trace context and baggage. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#composite-propagator

    TextMapCompositePropagator::extract_with_context

    Extracts using every child propagator in order. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#composite-propagator

    TextMapCompositePropagator::inject_context

    Injects using every child propagator in order. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#composite-propagator

    TextMapCompositePropagator::into_text_map

    Erases the concrete composite propagator type into TextMapPropagator. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#composite-propagator

    TextMapCompositePropagator::new

    Creates a propagator that runs multiple propagators in order.

    Injection runs every propagator. Extraction threads the context through the propagators from left to right. Reported fields are de-duplicated. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#composite-propagator

    TextMapPropagator

    Erased text-map propagator built from inject/extract callbacks.

    Use this as the common type for concrete propagators and custom propagation formats. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-propagator

    TextMapPropagator::extract_with_context

    Extracts values from the carrier and returns an updated context.

    Call this when handling an inbound request, then use the returned context as the parent context for server spans and downstream work. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-extract

    TextMapPropagator::fields

    fn TextMapPropagator::fields(self : TextMapPropagator) -> Array[String]

    Returns the header names this propagator may read or write. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#fields

    TextMapPropagator::from_functions

    Creates a custom text-map propagator from inject/extract/fields callbacks. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-propagator

    TextMapPropagator::inject_context

    Injects values from context into the supplied carrier.

    Call this before making an outbound request so downstream services can join the same trace and receive baggage. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-inject

    TraceContextPropagator

    pub struct TraceContextPropagator {
    inner : TextMapPropagator
    }

    W3C trace-context propagator wrapper.

    Reads and writes traceparent and tracestate. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#w3c-trace-context-requirements

    TraceContextPropagator::extract_with_context

    Extracts a remote span context from the carrier when the headers are valid. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-extract

    TraceContextPropagator::inject_context

    Injects the current span context into the carrier when it is valid. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#textmap-inject

    TraceContextPropagator::into_text_map

    Erases the concrete trace-context propagator type into TextMapPropagator. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#w3c-trace-context-requirements

    TraceContextPropagator::new

    Creates a trace-context propagator that reads and writes traceparent and tracestate.

    Invalid headers are ignored and leave the incoming context unchanged. Spec: https://opentelemetry.io/docs/specs/otel/context/api-propagators/#w3c-trace-context-requirements

    Source Files