fastrace::future

Trait FutureExt

Source
pub trait FutureExt: Future + Sized {
    // Provided methods
    fn in_span(self, span: Span) -> InSpan<Self>  { ... }
    fn enter_on_poll(
        self,
        name: impl Into<Cow<'static, str>>,
    ) -> EnterOnPoll<Self>  { ... }
}
Expand description

An extension trait for Futures that provides tracing instrument adapters.

Provided Methods§

Source

fn in_span(self, span: Span) -> InSpan<Self>

Binds a Span to the Future that continues to record until the future is dropped.

In addition, it sets the span as the local parent at every poll so that LocalSpan becomes available within the future. Internally, it calls Span::set_local_parent when the executor poll it.

§Examples
use fastrace::prelude::*;

let root = Span::root("Root", SpanContext::random());
let task = async {
    // ...
}
.in_span(Span::enter_with_parent("Task", &root));

tokio::spawn(task);
Source

fn enter_on_poll(self, name: impl Into<Cow<'static, str>>) -> EnterOnPoll<Self>

Starts a LocalSpan at every Future::poll(). If the future gets polled multiple times, it will create multiple short spans.

§Examples
use fastrace::prelude::*;

let root = Span::root("Root", SpanContext::random());
let task = async {
    async {
        // ...
    }
    .enter_on_poll("Sub Task")
    .await
}
.in_span(Span::enter_with_parent("Task", &root));

tokio::spawn(task);

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: Future> FutureExt for T