logo
pub struct TextMapCompositePropagator { /* private fields */ }
Available on crate feature trace only.
Expand description

Composite propagator

A propagator that chains multiple TextMapPropagator propagators together, injecting or extracting by their respective HTTP header names.

Injection and extraction from this propagator will preserve the order of the injectors and extractors passed in during initialization.

Examples

use opentelemetry_api::{
    baggage::BaggageExt,
    propagation::TextMapPropagator,
    trace::{TraceContextExt, Tracer, TracerProvider},
    Context, KeyValue,
};
use opentelemetry_sdk::propagation::{
    BaggagePropagator, TextMapCompositePropagator, TraceContextPropagator,
};
use opentelemetry_sdk::trace as sdktrace;
use std::collections::HashMap;

// First create 1 or more propagators
let baggage_propagator = BaggagePropagator::new();
let trace_context_propagator = TraceContextPropagator::new();

// Then create a composite propagator
let composite_propagator = TextMapCompositePropagator::new(vec![
    Box::new(baggage_propagator),
    Box::new(trace_context_propagator),
]);

// Then for a given implementation of `Injector`
let mut injector = HashMap::new();

// And a given span
let example_span = sdktrace::TracerProvider::default()
    .tracer("example-component")
    .start("span-name");

// with the current context, call inject to add the headers
composite_propagator.inject_context(
    &Context::current_with_span(example_span)
        .with_baggage(vec![KeyValue::new("test", "example")]),
    &mut injector,
);

// The injector now has both `baggage` and `traceparent` headers
assert!(injector.get("baggage").is_some());
assert!(injector.get("traceparent").is_some());

Implementations

Constructs a new propagator out of instances of TextMapPropagator.

Trait Implementations

Formats the value using the given formatter. Read more

Encodes the values of the Context and injects them into the Injector.

Retrieves encoded Context information using the Extractor. If no data was retrieved OR if the retrieved data is invalid, then the current Context is returned.

Returns iter of fields used by TextMapPropagator Read more

Properly encodes the values of the current Context and injects them into the Injector. Read more

Retrieves encoded data using the provided Extractor. If no data for this format was retrieved OR if the retrieved data is invalid, then the current Context is returned. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more

Attaches the current Context to this type, returning a WithContext wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.