Skip to content

Commit 2493fec

Browse files
authored
fix: align baggage.remove() implementation (#2734)
1 parent 46a7cd6 commit 2493fec

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

opentelemetry/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Bug Fix: `InstrumentationScope` implementation for `PartialEq` and `Hash` fixed to include Attributes also.
1010
- *Breaking* Changed value type of `Baggage` from `Value` to `StringValue`
1111
- Updated `Baggage` constants to reflect latest standard (`MAX_KEY_VALUE_PAIRS` - 180 -> 64, `MAX_BYTES_FOR_ONE_PAIR` - removed) and increased insert performance see #[2284](https://github.com/open-telemetry/opentelemetry-rust/pull/2284).
12+
- *Breaking* Align `Baggage.remove()` signature with `.get()` to take the key as a reference
1213

1314
## 0.28.0
1415

opentelemetry/src/baggage.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ impl Baggage {
193193

194194
/// Removes a name from the baggage, returning the value
195195
/// corresponding to the name if the pair was previously in the map.
196-
pub fn remove<K: Into<Key>>(&mut self, key: K) -> Option<(StringValue, BaggageMetadata)> {
197-
self.inner.remove(&key.into())
196+
pub fn remove<K: AsRef<str>>(&mut self, key: K) -> Option<(StringValue, BaggageMetadata)> {
197+
self.inner.remove(key.as_ref())
198198
}
199199

200200
/// Returns the number of attributes for this baggage
@@ -584,4 +584,25 @@ mod tests {
584584
assert!(b.insert("c", StringValue::from("..")).is_none()); // exceeds MAX_LEN_OF_ALL_PAIRS
585585
assert_eq!(b.insert("c", StringValue::from("!")).unwrap(), ".".into()); // replaces existing
586586
}
587+
588+
#[test]
589+
fn test_crud_operations() {
590+
let mut baggage = Baggage::default();
591+
assert!(baggage.is_empty());
592+
593+
// create
594+
baggage.insert("foo", "1");
595+
assert_eq!(baggage.len(), 1);
596+
597+
// get
598+
assert_eq!(baggage.get("foo"), Some(&StringValue::from("1")));
599+
600+
// update
601+
baggage.insert("foo", "2");
602+
assert_eq!(baggage.get("foo"), Some(&StringValue::from("2")));
603+
604+
// delete
605+
baggage.remove("foo");
606+
assert!(baggage.is_empty());
607+
}
587608
}

0 commit comments

Comments
 (0)