opentelemetry::baggage

Trait BaggageExt

Source
pub trait BaggageExt {
    // Required methods
    fn with_baggage<T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>>(
        &self,
        baggage: T,
    ) -> Self;
    fn current_with_baggage<T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>>(
        baggage: T,
    ) -> Self;
    fn with_cleared_baggage(&self) -> Self;
    fn baggage(&self) -> &Baggage;
}
Expand description

Methods for sorting and retrieving baggage data in a context.

Required Methods§

Source

fn with_baggage<T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>>( &self, baggage: T, ) -> Self

Returns a clone of the given context with the included name/value pairs.

§Examples
use opentelemetry::{baggage::BaggageExt, Context, KeyValue, Value};

let cx = Context::map_current(|cx| {
    cx.with_baggage(vec![KeyValue::new("my-name", "my-value")])
});

assert_eq!(
    cx.baggage().get("my-name"),
    Some(&Value::from("my-value")),
)
Source

fn current_with_baggage<T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>>( baggage: T, ) -> Self

Returns a clone of the current context with the included name/value pairs.

§Examples
use opentelemetry::{baggage::BaggageExt, Context, KeyValue, Value};

let cx = Context::current_with_baggage(vec![KeyValue::new("my-name", "my-value")]);

assert_eq!(
    cx.baggage().get("my-name"),
    Some(&Value::from("my-value")),
)
Source

fn with_cleared_baggage(&self) -> Self

Returns a clone of the given context with no baggage.

§Examples
use opentelemetry::{baggage::BaggageExt, Context, KeyValue, Value};

let cx = Context::map_current(|cx| cx.with_cleared_baggage());

assert_eq!(cx.baggage().len(), 0);
Source

fn baggage(&self) -> &Baggage

Returns a reference to this context’s baggage, or the default empty baggage if none has been set.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§