Struct tracing_subscriber::layer::Context[][src]

pub struct Context<'a, S> { /* fields omitted */ }
Expand description

Represents information about the current context provided to Layers by the wrapped Subscriber.

To access stored data keyed by a span ID, implementors of the Layer trait should ensure that the Subscriber type parameter is also bound by the LookupSpan:

use tracing::Subscriber;
use tracing_subscriber::{Layer, registry::LookupSpan};

pub struct MyLayer;

impl<S> Layer<S> for MyLayer
where
    S: Subscriber + for<'a> LookupSpan<'a>,
{
    // ...
}

Implementations

Returns the wrapped subscriber’s view of the current span.

Returns whether the wrapped subscriber would enable the current span.

Records the provided event with the wrapped subscriber.

Notes

  • The subscriber is free to expect that the event’s callsite has been registered, and may panic or fail to observe the event if this is not the case. The tracing crate’s macros ensure that all events are registered, but if the event is constructed through other means, the user is responsible for ensuring that register_callsite has been called prior to calling this method.
  • This does not call enabled on the inner subscriber. If the caller wishes to apply the wrapped subscriber’s filter before choosing whether to record the event, it may first call Context::enabled to check whether the event would be enabled. This allows Layers to elide constructing the event if it would not be recorded.
This is supported on crate feature registry only.

Returns metadata for the span with the given id, if it exists.

If this returns None, then no span exists for that ID (either it has closed or the ID is invalid).

This is supported on crate feature registry only.

Returns stored data for the span with the given id, if it exists.

If this returns None, then no span exists for that ID (either it has closed or the ID is invalid).

Note
Note: This requires the wrapped subscriber to implement the
LookupSpan trait.
See the documentation on Context's
declaration for details.
This is supported on crate feature registry only.

Returns true if an active span exists for the given Id.

Note
Note: This requires the wrapped subscriber to implement the
LookupSpan trait.
See the documentation on Context's
declaration for details.
This is supported on crate feature registry only.

Returns stored data for the span that the wrapped subscriber considers to be the current.

If this returns None, then we are not currently within a span.

Note
Note: This requires the wrapped subscriber to implement the
LookupSpan trait.
See the documentation on Context's
declaration for details.
This is supported on crate feature registry only.

Returns an iterator over the stored data for all the spans in the current context, starting the root of the trace tree and ending with the current span.

If this iterator is empty, then there are no spans in the current context.

Note
Note: This requires the wrapped subscriber to implement the
LookupSpan trait.
See the documentation on Context's
declaration for details.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

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

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

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.