Struct opentelemetry::baggage::Baggage
source · pub struct Baggage { /* private fields */ }
Expand description
A set of name/value pairs describing user-defined properties.
§Baggage Names
- ASCII strings according to the token format, defined in RFC2616, Section 2.2
§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
impl Baggage
sourcepub fn get<T: Into<Key>>(&self, key: T) -> Option<&Value>
pub fn get<T: Into<Key>>(&self, key: T) -> 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")))
sourcepub fn get_with_metadata<T: Into<Key>>(
&self,
key: T,
) -> Option<&(Value, BaggageMetadata)>
pub fn get_with_metadata<T: Into<Key>>( &self, key: T, ) -> 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(""))))
sourcepub fn insert<K, V>(&mut self, key: K, value: V) -> Option<Value>
pub fn insert<K, V>(&mut self, key: K, value: V) -> Option<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")))
sourcepub fn insert_with_metadata<K, V, S>(
&mut self,
key: K,
value: V,
metadata: S,
) -> Option<(Value, BaggageMetadata)>
pub fn insert_with_metadata<K, V, S>( &mut self, key: K, value: V, metadata: S, ) -> Option<(Value, 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"))))
Trait Implementations§
source§impl FromIterator<(Key, (Value, BaggageMetadata))> for Baggage
impl FromIterator<(Key, (Value, BaggageMetadata))> for Baggage
source§fn from_iter<I: IntoIterator<Item = (Key, (Value, BaggageMetadata))>>(
iter: I,
) -> Self
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
impl FromIterator<KeyValue> for Baggage
source§impl FromIterator<KeyValueMetadata> for Baggage
impl FromIterator<KeyValueMetadata> for Baggage
source§fn from_iter<I: IntoIterator<Item = KeyValueMetadata>>(iter: I) -> Self
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
impl<'a> IntoIterator for &'a Baggage
Auto Trait Implementations§
impl Freeze for Baggage
impl RefUnwindSafe for Baggage
impl Send for Baggage
impl Sync for Baggage
impl Unpin for Baggage
impl UnwindSafe for Baggage
Blanket Implementations§
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