Skip to content

Commit 866ae41

Browse files
authored
feat(global): set default propagator to noop (open-telemetry#329)
1 parent e87c435 commit 866ae41

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

opentelemetry/src/global/propagation.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use crate::propagation::TextMapPropagator;
2-
use crate::sdk::propagation::{
3-
BaggagePropagator, TextMapCompositePropagator, TraceContextPropagator,
4-
};
2+
use crate::sdk::propagation::TextMapCompositePropagator;
53
use std::sync::RwLock;
64

75
lazy_static::lazy_static! {
86
/// The current global `TextMapPropagator` propagator.
9-
static ref GLOBAL_TEXT_MAP_PROPAGATOR: RwLock<Box<dyn TextMapPropagator + Send + Sync>> = RwLock::new(Box::new(TextMapCompositePropagator::new(vec![Box::new(TraceContextPropagator::new()), Box::new(BaggagePropagator::new())])));
7+
static ref GLOBAL_TEXT_MAP_PROPAGATOR: RwLock<Box<dyn TextMapPropagator + Send + Sync>> = RwLock::new(Box::new(TextMapCompositePropagator::new(vec![])));
108
/// The global default `TextMapPropagator` propagator.
11-
static ref DEFAULT_TEXT_MAP_PROPAGATOR: TextMapCompositePropagator = TextMapCompositePropagator::new(vec![Box::new(TraceContextPropagator::new()), Box::new(BaggagePropagator::new())]);
9+
static ref DEFAULT_TEXT_MAP_PROPAGATOR: TextMapCompositePropagator = TextMapCompositePropagator::new(vec![]);
1210
}
1311

1412
/// Sets the given [`TextMapPropagator`] propagator as the current global propagator.

opentelemetry/src/sdk/propagation/composite.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,34 @@ mod tests {
186186
]
187187
}
188188

189+
#[test]
190+
fn zero_propogators_are_noop() {
191+
let composite_propagator = TextMapCompositePropagator::new(vec![]);
192+
193+
let cx = Context::default().with_span(TestSpan(SpanContext::new(
194+
TraceId::from_u128(1),
195+
SpanId::from_u64(1),
196+
0,
197+
false,
198+
TraceState::default(),
199+
)));
200+
let mut injector = HashMap::new();
201+
composite_propagator.inject_context(&cx, &mut injector);
202+
203+
assert_eq!(injector.len(), 0);
204+
205+
for (header_name, header_value) in test_data() {
206+
let mut extractor = HashMap::new();
207+
extractor.insert(header_name.to_string(), header_value.to_string());
208+
assert_eq!(
209+
composite_propagator
210+
.extract(&extractor)
211+
.remote_span_context(),
212+
None
213+
);
214+
}
215+
}
216+
189217
#[test]
190218
fn inject_multiple_propagators() {
191219
let test_propagator = TestPropagator::new();

0 commit comments

Comments
 (0)