Struct opentelemetry::baggage::Baggage

source ·
pub struct Baggage { /* private fields */ }
Expand description

A set of name/value pairs describing user-defined properties.

§Baggage Names

§Baggage Values

  • URL encoded UTF-8 strings.

§Baggage Value Metadata

Additional metadata can be added to values in the form of a property set, represented as semi-colon ; delimited list of names and/or name/value pairs, e.g. ;k1=v1;k2;k3=v3.

§Limits

  • Maximum number of name/value pairs: 180.
  • Maximum number of bytes per a single name/value pair: 4096.
  • Maximum total length of all name/value pairs: 8192.

Implementations§

source§

impl Baggage

source

pub fn new() -> Self

Creates an empty Baggage.

source

pub fn get<K: AsRef<str>>(&self, key: K) -> Option<&Value>

Returns a reference to the value associated with a given name

§Examples
use opentelemetry::{baggage::Baggage, Value};

let mut cc = Baggage::new();
let _ = cc.insert("my-name", "my-value");

assert_eq!(cc.get("my-name"), Some(&Value::from("my-value")))
source

pub fn get_with_metadata<K: AsRef<str>>( &self, key: K, ) -> Option<&(Value, BaggageMetadata)>

Returns a reference to the value and metadata associated with a given name

§Examples
use opentelemetry::{baggage::{Baggage, BaggageMetadata}, Value};

let mut cc = Baggage::new();
let _ = cc.insert("my-name", "my-value");

// By default, the metadata is empty
assert_eq!(cc.get_with_metadata("my-name"), Some(&(Value::from("my-value"), BaggageMetadata::from(""))))
source

pub fn insert<K, V>(&mut self, key: K, value: V) -> Option<Value>
where K: Into<Key>, V: Into<Value>,

Inserts a name/value pair into the baggage.

If the name was not present, None is returned. If the name was present, the value is updated, and the old value is returned.

§Examples
use opentelemetry::{baggage::Baggage, Value};

let mut cc = Baggage::new();
let _ = cc.insert("my-name", "my-value");

assert_eq!(cc.get("my-name"), Some(&Value::from("my-value")))
source

pub fn insert_with_metadata<K, V, S>( &mut self, key: K, value: V, metadata: S, ) -> Option<(Value, BaggageMetadata)>
where K: Into<Key>, V: Into<Value>, S: Into<BaggageMetadata>,

Inserts a name/value pair into the baggage.

Same with insert, if the name was not present, None will be returned. If the name is present, the old value and metadata will be returned.

§Examples
use opentelemetry::{baggage::{Baggage, BaggageMetadata}, Value};

let mut cc = Baggage::new();
let _ = cc.insert_with_metadata("my-name", "my-value", "test");

assert_eq!(cc.get_with_metadata("my-name"), Some(&(Value::from("my-value"), BaggageMetadata::from("test"))))
source

pub fn remove<K: Into<Key>>( &mut self, key: K, ) -> Option<(Value, BaggageMetadata)>

Removes a name from the baggage, returning the value corresponding to the name if the pair was previously in the map.

source

pub fn len(&self) -> usize

Returns the number of attributes for this baggage

source

pub fn is_empty(&self) -> bool

Returns true if the baggage contains no items.

source

pub fn iter(&self) -> Iter<'_>

Gets an iterator over the baggage items, sorted by name.

Trait Implementations§

source§

impl Debug for Baggage

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Baggage

source§

fn default() -> Baggage

Returns the “default value” for a type. Read more
source§

impl Display for Baggage

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromIterator<(Key, (Value, BaggageMetadata))> for Baggage

source§

fn from_iter<I: IntoIterator<Item = (Key, (Value, BaggageMetadata))>>( iter: I, ) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<KeyValue> for Baggage

source§

fn from_iter<I: IntoIterator<Item = KeyValue>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl FromIterator<KeyValueMetadata> for Baggage

source§

fn from_iter<I: IntoIterator<Item = KeyValueMetadata>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<'a> IntoIterator for &'a Baggage

§

type Item = (&'a Key, &'a (Value, BaggageMetadata))

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

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

fn with_current_context(self) -> WithContext<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.