[][src]Trait tracing_futures::Instrument

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;
{ ... } }

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

Provided methods

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

Notable traits for Instrumented<T>

impl<T: Future> Future for Instrumented<T> type Output = T::Output;

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:

This example is not tested
use tracing_futures::Instrument;

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

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

fn in_current_span(self) -> Instrumented<Self>

Notable traits for Instrumented<T>

impl<T: Future> Future for Instrumented<T> type Output = T::Output;

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

This example is not tested
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());
Loading content...

Implementors

impl<T: Sized> Instrument for T[src]

Loading content...