Skip to content

Commit 28becc0

Browse files
fix: with_cleared_baggage (#3006)
Co-authored-by: Cijo Thomas <[email protected]>
1 parent cab5565 commit 28becc0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

opentelemetry/src/baggage.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl BaggageExt for Context {
412412
}
413413

414414
fn with_cleared_baggage(&self) -> Self {
415-
self.with_value(Baggage::new())
415+
self.with_baggage(Baggage::new())
416416
}
417417

418418
fn baggage(&self) -> &Baggage {
@@ -653,4 +653,28 @@ mod tests {
653653
baggage.insert("(example)", "1");
654654
assert!(baggage.is_empty());
655655
}
656+
657+
#[test]
658+
fn test_context_clear_baggage() {
659+
let ctx = Context::new();
660+
let ctx = ctx.with_baggage([KeyValue::new("foo", 1)]);
661+
let _guard = ctx.attach();
662+
663+
{
664+
let ctx = Context::current();
665+
let baggage = ctx.baggage();
666+
// At this point baggage should still contain the inital value.
667+
assert_eq!(baggage.len(), 1);
668+
669+
// Baggage gets cleared.
670+
let ctx = ctx.with_cleared_baggage();
671+
let _guard = ctx.attach();
672+
{
673+
let ctx = Context::current();
674+
let baggage = ctx.baggage();
675+
// Baggage should contain no entries.
676+
assert_eq!(baggage.len(), 0);
677+
}
678+
}
679+
}
656680
}

0 commit comments

Comments
 (0)