Trait opentelemetry::baggage::BaggageExt
source · pub trait BaggageExt {
// Required methods
fn with_baggage<T, I>(&self, baggage: T) -> Self
where T: IntoIterator<Item = I>,
I: Into<KeyValueMetadata>;
fn current_with_baggage<T, I>(baggage: T) -> Self
where T: IntoIterator<Item = I>,
I: Into<KeyValueMetadata>;
fn with_cleared_baggage(&self) -> Self;
fn baggage(&self) -> &Baggage;
}
Expand description
Methods for sorting and retrieving baggage data in a context.
Required Methods§
sourcefn with_baggage<T, I>(&self, baggage: T) -> Selfwhere
T: IntoIterator<Item = I>,
I: Into<KeyValueMetadata>,
fn with_baggage<T, I>(&self, baggage: T) -> Selfwhere T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>,
Returns a clone of the given context with the included name/value pairs.
Examples
use opentelemetry_api::{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")),
)
sourcefn current_with_baggage<T, I>(baggage: T) -> Selfwhere
T: IntoIterator<Item = I>,
I: Into<KeyValueMetadata>,
fn current_with_baggage<T, I>(baggage: T) -> Selfwhere T: IntoIterator<Item = I>, I: Into<KeyValueMetadata>,
Returns a clone of the current context with the included name/value pairs.
Examples
use opentelemetry_api::{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")),
)
sourcefn with_cleared_baggage(&self) -> Self
fn with_cleared_baggage(&self) -> Self
Returns a clone of the given context with no baggage.
Examples
use opentelemetry_api::{baggage::BaggageExt, Context, KeyValue, Value};
let cx = Context::map_current(|cx| cx.with_cleared_baggage());
assert_eq!(cx.baggage().len(), 0);