logo
pub trait Instrument: Sized {
    fn instrument(self, span: Span) -> Instrumented<Self>Notable traits for Instrumented<T>impl<T: Future> Future for Instrumented<T>    type Output = T::Output; { ... }
    fn in_current_span(self) -> Instrumented<Self>Notable traits for Instrumented<T>impl<T: Future> Future for Instrumented<T>    type Output = T::Output; { ... }
}
Expand description

Extension trait allowing futures, streams, sinks, and executors to be instrumented with a tracing span.

Provided Methods

Instruments this type with the provided Span, returning an Instrumented wrapper.

If the instrumented type is a future, stream, or sink, the attached Span will be entered every time it is polled. If the instrumented type is a future executor, every future spawned on that executor will be instrumented by the attached Span.

Examples

Instrumenting a future:

use tracing_futures::Instrument;

let my_future = async {
    // ...
};

my_future
    .instrument(tracing::info_span!("my_future"))
    .await

Instruments this type with the current Span, returning an Instrumented wrapper.

If the instrumented type is a future, stream, or sink, the attached Span will be entered every time it is polled. If the instrumented type is a future executor, every future spawned on that executor will be instrumented by the attached Span.

This can be used to propagate the current span when spawning a new future.

Examples
use tracing_futures::Instrument;

let span = tracing::info_span!("my_span");
let _enter = span.enter();

// ...

let future = async {
    tracing::debug!("this event will occur inside `my_span`");
    // ...
};
tokio::spawn(future.in_current_span());

Implementors