Skip to content

Commit

Permalink
Use Context::map_current() instead of current()
Browse files Browse the repository at this point in the history
  • Loading branch information
shaun-cox committed Jul 4, 2023
1 parent 29a7b75 commit 8c2c38b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions opentelemetry-api/src/propagation/text_map_propagator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait TextMapPropagator: Debug {
/// [`Context`]: crate::Context
/// [`Injector`]: crate::propagation::Injector
fn inject(&self, injector: &mut dyn Injector) {
self.inject_context(&Context::current(), injector)
Context::map_current(|cx| self.inject_context(cx, injector))
}

/// Properly encodes the values of the [`Context`] and injects them into the
Expand All @@ -35,7 +35,7 @@ pub trait TextMapPropagator: Debug {
/// [`Context`]: crate::Context
/// [`Injector`]: crate::propagation::Extractor
fn extract(&self, extractor: &dyn Extractor) -> Context {
self.extract_with_context(&Context::current(), extractor)
Context::map_current(|cx| self.extract_with_context(cx, extractor))
}

/// Retrieves encoded data using the provided [`Extractor`]. If no data for this
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/src/trace/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub trait Tracer {
where
T: Into<Cow<'static, str>>,
{
self.build_with_context(SpanBuilder::from_name(name), &Context::current())
Context::map_current(|cx| self.start_with_context(name, cx))
}

/// Starts a new [`Span`] with a given context.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/src/propagation/trace_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ mod tests {
let mut injector: HashMap<String, String> = HashMap::new();
injector.set(TRACESTATE_HEADER, state.to_string());

propagator.inject_context(&Context::current(), &mut injector);
Context::map_current(|cx| propagator.inject_context(cx, &mut injector));

assert_eq!(Extractor::get(&injector, TRACESTATE_HEADER), Some(state))
}
Expand Down
7 changes: 4 additions & 3 deletions opentelemetry-sdk/src/trace/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,16 @@ mod tests {
let span = tracer.span_builder("must_not_be_sampled").start(&tracer);
assert!(!span.span_context().is_sampled());

let _attached = Context::current()
.with_remote_span_context(SpanContext::new(
let context = Context::map_current(|cx| {
cx.with_remote_span_context(SpanContext::new(
TraceId::from_u128(1),
SpanId::from_u64(1),
TraceFlags::default(),
true,
Default::default(),
))
.attach();
});
let _attached = context.attach();
let span = tracer.span_builder("must_not_be_sampled").start(&tracer);

assert!(!span.span_context().is_sampled());
Expand Down

0 comments on commit 8c2c38b

Please sign in to comment.