Runtime

Struct Runtime 

Source
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 Emitter to receive diagnostic events.
  • A Filter to limit the volume of diagnostic events.
  • A Ctxt to capture and attach ambient state to events.
  • A Clock to timestamp events.
  • A Rng to 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 Runtime

Source

pub const fn new() -> Runtime

Create a new, empty runtime.

Source§

impl<TEmitter, TFilter, TCtxt, TClock, TRng> Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>

Source

pub const fn build( emitter: TEmitter, filter: TFilter, ctxt: TCtxt, clock: TClock, rng: TRng, ) -> Self

Create a new runtime with the given components.

Source

pub const fn emitter(&self) -> &TEmitter

Get the Emitter.

Source

pub fn with_emitter<U>( self, emitter: U, ) -> Runtime<U, TFilter, TCtxt, TClock, TRng>

Set the Emitter.

Source

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.

Source

pub const fn filter(&self) -> &TFilter

Get the Filter.

Source

pub fn with_filter<U>( self, filter: U, ) -> Runtime<TEmitter, U, TCtxt, TClock, TRng>

Set the Filter.

Source

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.

Source

pub const fn ctxt(&self) -> &TCtxt

Get the Ctxt.

Source

pub fn with_ctxt<U>( self, ctxt: U, ) -> Runtime<TEmitter, TFilter, U, TClock, TRng>

Set the Ctxt.

Source

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.

Source

pub const fn clock(&self) -> &TClock

Get the Clock.

Source

pub fn with_clock<U>( self, clock: U, ) -> Runtime<TEmitter, TFilter, TCtxt, U, TRng>

Set the Clock.

Source

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

pub const fn rng(&self) -> &TRng

Get the Rng.

Source

pub fn with_rng<U>( self, id_gen: U, ) -> Runtime<TEmitter, TFilter, TCtxt, TClock, U>

Set the Rng.

Source

pub fn map_rng<U>( self, id_gen: impl FnOnce(TRng) -> U, ) -> Runtime<TEmitter, TFilter, TCtxt, TClock, U>

Map the current Rng to a new value.

Source§

impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>

Source

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:

  1. Attempt to assign an extent to the event using Clock::now if the event doesn’t already have one.
  2. Add Ctxt::Current to the event properties.
  3. Ensure the event passes Filter::matches.
  4. Emit the event through Emitter::emit.

You can bypass any of these steps by emitting the event directly through the runtime’s Emitter.

Source

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.

Trait Implementations§

Source§

impl<TEmitter: Clone, TFilter: Clone, TCtxt: Clone, TClock: Clone, TRng: Clone> Clone for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>

Source§

fn clone(&self) -> Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<TEmitter: Debug, TFilter: Debug, TCtxt: Debug, TClock: Debug, TRng: Debug> Debug for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Runtime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<TEmitter: Emitter, TFilter: Filter, TCtxt: Ctxt, TClock: Clock, TRng: Rng> Emitter for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>

Source§

fn emit<E: ToEvent>(&self, evt: E)

Emit an Event.
Source§

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. Read more
Source§

fn and_to<U>(self, other: U) -> And<Self, U>
where Self: Sized,

Emit events to both self and other.
Source§

fn wrap_emitter<W: Wrapping>(self, wrapping: W) -> Wrap<Self, W>
where Self: Sized,

Wrap the emitter, transforming or filtering Events before it receives them. Read more
Source§

impl<TEmitter: Copy, TFilter: Copy, TCtxt: Copy, TClock: Copy, TRng: Copy> Copy for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>

Auto Trait Implementations§

§

impl<TEmitter, TFilter, TCtxt, TClock, TRng> Freeze for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
where TEmitter: Freeze, TFilter: Freeze, TCtxt: Freeze, TClock: Freeze, TRng: Freeze,

§

impl<TEmitter, TFilter, TCtxt, TClock, TRng> RefUnwindSafe for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
where TEmitter: RefUnwindSafe, TFilter: RefUnwindSafe, TCtxt: RefUnwindSafe, TClock: RefUnwindSafe, TRng: RefUnwindSafe,

§

impl<TEmitter, TFilter, TCtxt, TClock, TRng> Send for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
where TEmitter: Send, TFilter: Send, TCtxt: Send, TClock: Send, TRng: Send,

§

impl<TEmitter, TFilter, TCtxt, TClock, TRng> Sync for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
where TEmitter: Sync, TFilter: Sync, TCtxt: Sync, TClock: Sync, TRng: Sync,

§

impl<TEmitter, TFilter, TCtxt, TClock, TRng> Unpin for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
where TEmitter: Unpin, TFilter: Unpin, TCtxt: Unpin, TClock: Unpin, TRng: Unpin,

§

impl<TEmitter, TFilter, TCtxt, TClock, TRng> UnwindSafe for Runtime<TEmitter, TFilter, TCtxt, TClock, TRng>
where TEmitter: UnwindSafe, TFilter: UnwindSafe, TCtxt: UnwindSafe, TClock: UnwindSafe, TRng: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedEmitter for T
where T: Emitter,