pub struct Runtime<TEmitter = Empty, TFilter = Empty, TCtxt = Empty, TClock = Empty, TRng = Empty> { /* private fields */ }Expand description
A diagnostic pipeline.
Each runtime includes the following components:
- An
Emitterto receive diagnostic events. - A
Filterto limit the volume of diagnostic events. - A
Ctxtto capture and attach ambient state to events. - A
Clockto timestamp events. - A
Rngto generate correlation ids for events.
The components of a runtime can be accessed directly through methods. A runtime can be treated like a builder to set its components, or initialized with them all directly.
In statics, you can also use the AmbientSlot type to hold a type-erased runtime. It’s also reasonable to store a fully generic runtime in a static too.
Implementations§
Source§impl<TEmitter, TFilter, TCtxt, TClock, TRng> Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
impl<TEmitter, TFilter, TCtxt, TClock, TRng> Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
Sourcepub const fn build(
emitter: TEmitter,
filter: TFilter,
ctxt: TCtxt,
clock: TClock,
rng: TRng,
) -> Self
pub const fn build( emitter: TEmitter, filter: TFilter, ctxt: TCtxt, clock: TClock, rng: TRng, ) -> Self
Create a new runtime with the given components.
Sourcepub fn with_emitter<U>(
self,
emitter: U,
) -> Runtime<U, TFilter, TCtxt, TClock, TRng>
pub fn with_emitter<U>( self, emitter: U, ) -> Runtime<U, TFilter, TCtxt, TClock, TRng>
Set the Emitter.
Sourcepub fn map_emitter<U>(
self,
emitter: impl FnOnce(TEmitter) -> U,
) -> Runtime<U, TFilter, TCtxt, TClock, TRng>
pub fn map_emitter<U>( self, emitter: impl FnOnce(TEmitter) -> U, ) -> Runtime<U, TFilter, TCtxt, TClock, TRng>
Map the current Emitter to a new value.
Sourcepub fn with_filter<U>(
self,
filter: U,
) -> Runtime<TEmitter, U, TCtxt, TClock, TRng>
pub fn with_filter<U>( self, filter: U, ) -> Runtime<TEmitter, U, TCtxt, TClock, TRng>
Set the Filter.
Sourcepub fn map_filter<U>(
self,
filter: impl FnOnce(TFilter) -> U,
) -> Runtime<TEmitter, U, TCtxt, TClock, TRng>
pub fn map_filter<U>( self, filter: impl FnOnce(TFilter) -> U, ) -> Runtime<TEmitter, U, TCtxt, TClock, TRng>
Map the current Filter to a new value.
Sourcepub fn with_ctxt<U>(
self,
ctxt: U,
) -> Runtime<TEmitter, TFilter, U, TClock, TRng>
pub fn with_ctxt<U>( self, ctxt: U, ) -> Runtime<TEmitter, TFilter, U, TClock, TRng>
Set the Ctxt.
Sourcepub fn map_ctxt<U>(
self,
ctxt: impl FnOnce(TCtxt) -> U,
) -> Runtime<TEmitter, TFilter, U, TClock, TRng>
pub fn map_ctxt<U>( self, ctxt: impl FnOnce(TCtxt) -> U, ) -> Runtime<TEmitter, TFilter, U, TClock, TRng>
Map the current Ctxt to a new value.
Sourcepub fn with_clock<U>(
self,
clock: U,
) -> Runtime<TEmitter, TFilter, TCtxt, U, TRng>
pub fn with_clock<U>( self, clock: U, ) -> Runtime<TEmitter, TFilter, TCtxt, U, TRng>
Set the Clock.
Sourcepub fn map_clock<U>(
self,
clock: impl FnOnce(TClock) -> U,
) -> Runtime<TEmitter, TFilter, TCtxt, U, TRng>
pub fn map_clock<U>( self, clock: impl FnOnce(TClock) -> U, ) -> Runtime<TEmitter, TFilter, TCtxt, U, TRng>
Map the current Clock to a new value.
Source§impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
Sourcepub fn emit<E: ToEvent>(&self, evt: E)
pub fn emit<E: ToEvent>(&self, evt: E)
Emit a diagnostic event through the runtime.
This method uses the components of the runtime to process the event. It will:
- Attempt to assign an extent to the event using
Clock::nowif the event doesn’t already have one. - Add
Ctxt::Currentto the event properties. - Ensure the event passes
Filter::matches. - Emit the event through
Emitter::emit.
You can bypass any of these steps by emitting the event directly through the runtime’s Emitter.
Sourcepub fn blocking_flush(&self, timeout: Duration) -> bool
pub fn blocking_flush(&self, timeout: Duration) -> bool
Block for up to timeout, waiting for all diagnostic data emitted up to this point to be fully processed.
This method defers to the runtime’s Emitter::blocking_flush.