Struct TextMapCompositePropagator
pub struct TextMapCompositePropagator { /* private fields */ }
Expand description
Composite propagator for TextMapPropagator
s.
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::{
baggage::BaggageExt,
propagation::{TextMapPropagator, TextMapCompositePropagator},
trace::{TraceContextExt, Tracer, TracerProvider},
Context, KeyValue,
};
use opentelemetry_sdk::propagation::{
BaggagePropagator, 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::SdkTracerProvider::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§
§impl TextMapCompositePropagator
impl TextMapCompositePropagator
pub fn new(
propagators: Vec<Box<dyn TextMapPropagator + Sync + Send>>,
) -> TextMapCompositePropagator
pub fn new( propagators: Vec<Box<dyn TextMapPropagator + Sync + Send>>, ) -> TextMapCompositePropagator
Constructs a new propagator out of instances of TextMapPropagator
.
Trait Implementations§
§impl Debug for TextMapCompositePropagator
impl Debug for TextMapCompositePropagator
§impl TextMapPropagator for TextMapCompositePropagator
impl TextMapPropagator for TextMapCompositePropagator
§fn inject_context(&self, context: &Context, injector: &mut dyn Injector)
fn inject_context(&self, context: &Context, injector: &mut dyn Injector)
Encodes the values of the Context
and injects them into the Injector
.
§fn extract_with_context(
&self,
cx: &Context,
extractor: &dyn Extractor,
) -> Context
fn extract_with_context( &self, cx: &Context, extractor: &dyn Extractor, ) -> Context
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.
§fn fields(&self) -> FieldIter<'_> ⓘ
fn fields(&self) -> FieldIter<'_> ⓘ
Returns iter of fields used by
TextMapPropagator
Auto Trait Implementations§
impl Freeze for TextMapCompositePropagator
impl !RefUnwindSafe for TextMapCompositePropagator
impl Send for TextMapCompositePropagator
impl Sync for TextMapCompositePropagator
impl Unpin for TextMapCompositePropagator
impl !UnwindSafe for TextMapCompositePropagator
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Create a new
Policy
that returns Action::Follow
only if self
and other
return
Action::Follow
. Read more