tracing_futures

Trait Instrument

Source
pub trait Instrument: Sized {
    // Provided methods
    fn instrument(self, span: Span) -> Instrumented<Self>  { ... }
    fn in_current_span(self) -> Instrumented<Self>  { ... }
}
Expand description

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

Provided Methods§

Source

fn instrument(self, span: Span) -> Instrumented<Self>

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
Source

fn in_current_span(self) -> Instrumented<Self>

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());

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Sized> Instrument for T