13
13
//! Baggage can be sent between systems using a baggage propagator in
14
14
//! accordance with the [W3C Baggage] specification.
15
15
//!
16
+ //! Note: Baggage is not automatically added to any telemetry. Users have to
17
+ //! explicitly add baggage entries to telemetry items.
18
+ //!
19
+ //!
16
20
//! [W3C Baggage]: https://w3c.github.io/baggage
17
21
use crate :: { Context , Key , KeyValue , StringValue } ;
18
22
use std:: collections:: hash_map:: Entry ;
@@ -75,10 +79,10 @@ impl Baggage {
75
79
/// ```
76
80
/// use opentelemetry::{baggage::Baggage, StringValue};
77
81
///
78
- /// let mut cc = Baggage::new();
79
- /// let _ = cc .insert("my-name", "my-value");
82
+ /// let mut baggage = Baggage::new();
83
+ /// let _ = baggage .insert("my-name", "my-value");
80
84
///
81
- /// assert_eq!(cc .get("my-name"), Some(&StringValue::from("my-value")))
85
+ /// assert_eq!(baggage .get("my-name"), Some(&StringValue::from("my-value")))
82
86
/// ```
83
87
pub fn get < K : AsRef < str > > ( & self , key : K ) -> Option < & StringValue > {
84
88
self . inner . get ( key. as_ref ( ) ) . map ( |( value, _metadata) | value)
@@ -90,11 +94,11 @@ impl Baggage {
90
94
/// ```
91
95
/// use opentelemetry::{baggage::{Baggage, BaggageMetadata}, StringValue};
92
96
///
93
- /// let mut cc = Baggage::new();
94
- /// let _ = cc .insert("my-name", "my-value");
97
+ /// let mut baggage = Baggage::new();
98
+ /// let _ = baggage .insert("my-name", "my-value");
95
99
///
96
100
/// // By default, the metadata is empty
97
- /// assert_eq!(cc .get_with_metadata("my-name"), Some(&(StringValue::from("my-value"), BaggageMetadata::from(""))))
101
+ /// assert_eq!(baggage .get_with_metadata("my-name"), Some(&(StringValue::from("my-value"), BaggageMetadata::from(""))))
98
102
/// ```
99
103
pub fn get_with_metadata < K : AsRef < str > > (
100
104
& self ,
@@ -113,10 +117,10 @@ impl Baggage {
113
117
/// ```
114
118
/// use opentelemetry::{baggage::Baggage, StringValue};
115
119
///
116
- /// let mut cc = Baggage::new();
117
- /// let _ = cc .insert("my-name", "my-value");
120
+ /// let mut baggage = Baggage::new();
121
+ /// let _ = baggage .insert("my-name", "my-value");
118
122
///
119
- /// assert_eq!(cc .get("my-name"), Some(&StringValue::from("my-value")))
123
+ /// assert_eq!(baggage .get("my-name"), Some(&StringValue::from("my-value")))
120
124
/// ```
121
125
pub fn insert < K , V > ( & mut self , key : K , value : V ) -> Option < StringValue >
122
126
where
@@ -127,7 +131,7 @@ impl Baggage {
127
131
. map ( |pair| pair. 0 )
128
132
}
129
133
130
- /// Inserts a name/value pair into the baggage.
134
+ /// Inserts a name/value(+metadata) pair into the baggage.
131
135
///
132
136
/// Same with `insert`, if the name was not present, [`None`] will be returned.
133
137
/// If the name is present, the old value and metadata will be returned.
@@ -139,10 +143,10 @@ impl Baggage {
139
143
/// ```
140
144
/// use opentelemetry::{baggage::{Baggage, BaggageMetadata}, StringValue};
141
145
///
142
- /// let mut cc = Baggage::new();
143
- /// let _ = cc .insert_with_metadata("my-name", "my-value", "test");
146
+ /// let mut baggage = Baggage::new();
147
+ /// let _ = baggage .insert_with_metadata("my-name", "my-value", "test");
144
148
///
145
- /// assert_eq!(cc .get_with_metadata("my-name"), Some(&(StringValue::from("my-value"), BaggageMetadata::from("test"))))
149
+ /// assert_eq!(baggage .get_with_metadata("my-name"), Some(&(StringValue::from("my-value"), BaggageMetadata::from("test"))))
146
150
/// ```
147
151
pub fn insert_with_metadata < K , V , S > (
148
152
& mut self ,
0 commit comments