Trait Instrument
trait Instrument: Sized
Attaches spans to a std::future::Future.
Extension trait allowing futures to be
instrumented with a tracing span.
Provided Methods
fn instrument(self: Self, span: Span) -> Instrumented<Self>Instruments this type with the provided
Span, returning anInstrumentedwrapper.The attached
Spanwill be entered every time the instrumentedFutureis polled orDropped.Examples
Instrumenting a future:
use Instrument; # asyncThe
Span::or_currentcombinator can be used in combination withinstrumentto ensure that the current span is attached to the future if the span passed toinstrumentis disabled:use Instrument; # let my_future = async ; let outer_span = info_span!.entered; // If the "my_future" span is enabled, then the spawned task will // be within both "my_future" *and* "outer", since "outer" is // "my_future"'s parent. However, if "my_future" is disabled, // the spawned task will *not* be in any span. spawn; // Using `Span::or_current` ensures the spawned task is instrumented // with the current span, if the new span passed to `instrument` is // not enabled. This means that if the "my_future" span is disabled, // the spawned task will still be instrumented with the "outer" span: # let my_future = async ; spawn;fn in_current_span(self: Self) -> Instrumented<Self>Instruments this type with the current
Span, returning anInstrumentedwrapper.The attached
Spanwill be entered every time the instrumentedFutureis polled orDropped.This can be used to propagate the current span when spawning a new future.
Examples
use Instrument; # # async
Implementors
impl<T> Instrument for Entered<'a>impl<T> Instrument for EnteredSpanimpl<T> Instrument for WithDispatch<T>impl<T> Instrument for Instrumented<T>impl<T: Sized> Instrument for Timpl<T> Instrument for Span