Skip to content

Commit 104d66d

Browse files
authored
Remove Tracer::with_span (open-telemetry#746)
* Remove `Tracer::with_span` This method is not part of the trace spec and the same functionality can be achieved with `mark_span_as_active` or `Context::current_with_span(span).attach()`. * Fix dynatrace clippy lints * fix otlp external example lint * Fix doc links
1 parent 152daee commit 104d66d

File tree

4 files changed

+4
-64
lines changed

4 files changed

+4
-64
lines changed

examples/external-otlp-tonic-tokio/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn init_tracer() -> Result<sdktrace::Tracer, TraceError> {
4747
.map(|(name, value)| {
4848
let header_name = name
4949
.strip_prefix(HEADER_PREFIX)
50-
.map(|h| h.replace("_", "-"))
50+
.map(|h| h.replace('_', "-"))
5151
.map(|h| h.to_ascii_lowercase())
5252
.unwrap();
5353
(header_name, value)

opentelemetry-api/src/trace/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@
9595
//! drop(active)
9696
//! ```
9797
//!
98-
//! Additionally [`Tracer::with_span`] and [`Tracer::in_span`] can be used as shorthand to
99-
//! simplify managing the parent context.
98+
//! Additionally [`Tracer::in_span`] can be used as shorthand to simplify
99+
//! managing the parent context.
100100
//!
101101
//! ```
102102
//! use opentelemetry_api::{global, trace::Tracer};
@@ -109,12 +109,6 @@
109109
//! tracer.in_span("parent_span", |cx| {
110110
//! // spans created here will be children of `parent_span`
111111
//! });
112-
//!
113-
//! // Use `with_span` to mark a span as active for a given period.
114-
//! let span = tracer.start("parent_span");
115-
//! tracer.with_span(span, |cx| {
116-
//! // spans created here will be children of `parent_span`
117-
//! });
118112
//! ```
119113
//!
120114
//! #### Async active spans

opentelemetry-api/src/trace/tracer.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,6 @@ use std::time::SystemTime;
4444
/// // child has ended, parent now the active span again
4545
/// });
4646
/// // parent has ended, no active spans
47-
///
48-
/// // -- OR --
49-
///
50-
/// // create complex spans with span builder and `with_span`
51-
/// let parent_span = tracer.span_builder("foo").with_kind(SpanKind::Server).start(&tracer);
52-
/// tracer.with_span(parent_span, |_foo_cx| {
53-
/// // parent span is active
54-
/// let child_span = tracer.span_builder("bar").with_kind(SpanKind::Client).start(&tracer);
55-
/// tracer.with_span(child_span, |_bar_cx| {
56-
/// // child span is now the active span and associated with the parent span
57-
/// });
58-
/// // child has ended, parent now the active span again
59-
/// });
60-
/// // parent has ended, no active spans
6147
/// ```
6248
///
6349
/// Spans can also be marked as active, and the resulting guard allows for
@@ -228,46 +214,6 @@ pub trait Tracer {
228214
let _guard = cx.clone().attach();
229215
f(cx)
230216
}
231-
232-
/// Execute the given closure with reference to a context in which the span is
233-
/// active.
234-
///
235-
/// This sets the given span as active for the duration of the given function.
236-
/// It then executes the body. It closes the span before returning the execution
237-
/// result.
238-
///
239-
/// # Examples
240-
///
241-
/// ```
242-
/// use opentelemetry_api::{global, trace::{Span, SpanKind, Tracer, get_active_span}, KeyValue};
243-
///
244-
/// fn my_function() {
245-
/// let tracer = global::tracer("my-component");
246-
/// // start a span with custom attributes via span builder
247-
/// let span = tracer.span_builder("span-name").with_kind(SpanKind::Server).start(&tracer);
248-
/// // Mark the span as active for the duration of the closure
249-
/// global::tracer("my-component").with_span(span, |_cx| {
250-
/// // anything happening in functions we call can still access the active span...
251-
/// my_other_function();
252-
/// })
253-
/// }
254-
///
255-
/// fn my_other_function() {
256-
/// // call methods on the current span from
257-
/// get_active_span(|span| {
258-
/// span.add_event("An event!".to_string(), vec![KeyValue::new("happened", true)]);
259-
/// })
260-
/// }
261-
/// ```
262-
fn with_span<T, F>(&self, span: Self::Span, f: F) -> T
263-
where
264-
F: FnOnce(Context) -> T,
265-
Self::Span: Send + Sync + 'static,
266-
{
267-
let cx = Context::current_with_span(span);
268-
let _guard = cx.clone().attach();
269-
f(cx)
270-
}
271217
}
272218

273219
/// `SpanBuilder` allows span attributes to be configured before the span

opentelemetry-dynatrace/tests/http_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ mod test {
116116
);
117117
assert_eq!(
118118
req.headers().get(AUTHORIZATION),
119-
Some(&HeaderValue::from_str(&"Api-Token 1234567890".to_string()).unwrap()),
119+
Some(&HeaderValue::from_str("Api-Token 1234567890").unwrap()),
120120
);
121121

122122
let bytes = body::to_bytes(req.into_body())

0 commit comments

Comments
 (0)