@@ -3,7 +3,7 @@ use crate::{
3
3
trace:: {
4
4
Event , Link , Span , SpanContext , SpanId , SpanKind , StatusCode , TraceContextExt , TraceId ,
5
5
} ,
6
- Context , ContextGuard , KeyValue ,
6
+ Context , KeyValue ,
7
7
} ;
8
8
use std:: fmt;
9
9
use std:: time:: SystemTime ;
@@ -86,15 +86,15 @@ use std::time::SystemTime;
86
86
/// greater control over when the span is no longer considered active.
87
87
///
88
88
/// ```
89
- /// use opentelemetry::{global, trace::{Span, Tracer}};
89
+ /// use opentelemetry::{global, trace::{Span, Tracer, mark_span_as_active }};
90
90
/// let tracer = global::tracer("my-component");
91
91
///
92
92
/// let parent_span = tracer.start("foo");
93
- /// let parent_active = tracer. mark_span_as_active(parent_span);
93
+ /// let parent_active = mark_span_as_active(parent_span);
94
94
///
95
95
/// {
96
96
/// let child = tracer.start("bar");
97
- /// let _child_active = tracer. mark_span_as_active(child);
97
+ /// let _child_active = mark_span_as_active(child);
98
98
///
99
99
/// // do work in the context of the child span...
100
100
///
@@ -115,12 +115,12 @@ use std::time::SystemTime;
115
115
/// the following example _will not_ work:
116
116
///
117
117
/// ```no_run
118
- /// # use opentelemetry::{global, trace::Tracer};
118
+ /// # use opentelemetry::{global, trace::{ Tracer, mark_span_as_active} };
119
119
/// # let tracer = global::tracer("foo");
120
120
/// # let span = tracer.start("foo-span");
121
121
/// async {
122
122
/// // Does not work
123
- /// let _g = tracer. mark_span_as_active(span);
123
+ /// let _g = mark_span_as_active(span);
124
124
/// // ...
125
125
/// };
126
126
/// ```
@@ -230,71 +230,6 @@ pub trait Tracer: fmt::Debug + 'static {
230
230
/// Create a span from a `SpanBuilder`
231
231
fn build_with_context ( & self , builder : SpanBuilder , cx : & Context ) -> Self :: Span ;
232
232
233
- /// Mark a given `Span` as active.
234
- ///
235
- /// The `Tracer` MUST provide a way to update its active `Span`, and MAY provide convenience
236
- /// methods to manage a `Span`'s lifetime and the scope in which a `Span` is active. When an
237
- /// active `Span` is made inactive, the previously-active `Span` SHOULD be made active. A `Span`
238
- /// maybe finished (i.e. have a non-null end time) but still be active. A `Span` may be active
239
- /// on one thread after it has been made inactive on another.
240
- ///
241
- /// # Examples
242
- ///
243
- /// ```
244
- /// use opentelemetry::{global, trace::{Span, Tracer}, KeyValue};
245
- ///
246
- /// fn my_function() {
247
- /// let tracer = global::tracer("my-component-a");
248
- /// // start an active span in one function
249
- /// let span = tracer.start("span-name");
250
- /// let _guard = tracer.mark_span_as_active(span);
251
- /// // anything happening in functions we call can still access the active span...
252
- /// my_other_function();
253
- /// }
254
- ///
255
- /// fn my_other_function() {
256
- /// // call methods on the current span from
257
- /// global::tracer("my-component-b").get_active_span(|span| {
258
- /// span.add_event("An event!".to_string(), vec![KeyValue::new("happened", true)]);
259
- /// });
260
- /// }
261
- /// ```
262
- #[ must_use = "Dropping the guard detaches the context." ]
263
- fn mark_span_as_active ( & self , span : Self :: Span ) -> ContextGuard {
264
- let cx = Context :: current_with_span ( span) ;
265
- cx. attach ( )
266
- }
267
-
268
- /// Executes a closure with a reference to this thread's current span.
269
- ///
270
- /// # Examples
271
- ///
272
- /// ```
273
- /// use opentelemetry::{global, trace::{Span, Tracer}, KeyValue};
274
- ///
275
- /// fn my_function() {
276
- /// // start an active span in one function
277
- /// global::tracer("my-component").in_span("span-name", |_cx| {
278
- /// // anything happening in functions we call can still access the active span...
279
- /// my_other_function();
280
- /// })
281
- /// }
282
- ///
283
- /// fn my_other_function() {
284
- /// // call methods on the current span from
285
- /// global::tracer("my-component").get_active_span(|span| {
286
- /// span.add_event("An event!".to_string(), vec![KeyValue::new("happened", true)]);
287
- /// })
288
- /// }
289
- /// ```
290
- fn get_active_span < F , T > ( & self , f : F ) -> T
291
- where
292
- F : FnOnce ( & dyn Span ) -> T ,
293
- Self : Sized ,
294
- {
295
- f ( Context :: current ( ) . span ( ) )
296
- }
297
-
298
233
/// Start a new span and execute the given closure with reference to the span's
299
234
/// context.
300
235
///
@@ -305,7 +240,7 @@ pub trait Tracer: fmt::Debug + 'static {
305
240
/// # Examples
306
241
///
307
242
/// ```
308
- /// use opentelemetry::{global, trace::{Span, Tracer}, KeyValue};
243
+ /// use opentelemetry::{global, trace::{Span, Tracer, get_active_span }, KeyValue};
309
244
///
310
245
/// fn my_function() {
311
246
/// // start an active span in one function
@@ -317,7 +252,7 @@ pub trait Tracer: fmt::Debug + 'static {
317
252
///
318
253
/// fn my_other_function() {
319
254
/// // call methods on the current span from
320
- /// global::tracer("my-component"). get_active_span(|span| {
255
+ /// get_active_span(|span| {
321
256
/// span.add_event("An event!".to_string(), vec![KeyValue::new("happened", true)]);
322
257
/// })
323
258
/// }
@@ -343,7 +278,7 @@ pub trait Tracer: fmt::Debug + 'static {
343
278
/// # Examples
344
279
///
345
280
/// ```
346
- /// use opentelemetry::{global, trace::{Span, SpanKind, Tracer}, KeyValue};
281
+ /// use opentelemetry::{global, trace::{Span, SpanKind, Tracer, get_active_span }, KeyValue};
347
282
///
348
283
/// fn my_function() {
349
284
/// let tracer = global::tracer("my-component");
@@ -358,7 +293,7 @@ pub trait Tracer: fmt::Debug + 'static {
358
293
///
359
294
/// fn my_other_function() {
360
295
/// // call methods on the current span from
361
- /// global::tracer("my-component"). get_active_span(|span| {
296
+ /// get_active_span(|span| {
362
297
/// span.add_event("An event!".to_string(), vec![KeyValue::new("happened", true)]);
363
298
/// })
364
299
/// }
0 commit comments