Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: align baggage.remove() implementation #2734

Merged
merged 5 commits into from
Mar 3, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions opentelemetry/src/baggage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ impl Baggage {

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

/// Returns the number of attributes for this baggage
Expand Down Expand Up @@ -608,4 +608,25 @@ mod tests {
assert!(b.to_string().contains("bar=2;yellow"));
assert!(b.to_string().contains("foo=1;red;state=on"));
}

#[test]
fn test_crud_operations() {
let mut baggage = Baggage::default();
assert!(baggage.is_empty());

// create
baggage.insert("foo", "1");
assert_eq!(baggage.len(), 1);

// get
assert_eq!(baggage.get("foo"), Some(&Value::from("1")));

// update
baggage.insert("foo", "2");
assert_eq!(baggage.get("foo"), Some(&Value::from("2")));

// delete
baggage.remove("foo");
assert!(baggage.is_empty());
}
}
Loading