A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.rs/tracing/latest/tracing/trait.Instrument.html below:

Instrument in tracing - Rust

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

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

The attached Span will be entered every time the instrumented Future is polled or Dropped.

§Examples

Instrumenting a future:

use tracing::Instrument;

let my_future = async {
    };

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

The Span::or_current combinator can be used in combination with instrument to ensure that the current span is attached to the future if the span passed to instrument is disabled:

use tracing::Instrument;

let my_future = async {
    };

let outer_span = tracing::info_span!("outer").entered();

tokio::spawn(
    my_future
        .instrument(tracing::debug_span!("my_future"))
);

tokio::spawn(
   my_future
        .instrument(tracing::debug_span!("my_future").or_current())
);
Source

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

The attached Span will be entered every time the instrumented Future is polled or Dropped.

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

§Examples
use tracing::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());

This trait is not dyn compatible.

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4