Skip to main content

WideEventGuard

Struct WideEventGuard 

Source
pub struct WideEventGuard(/* private fields */);
Expand description

RAII guard that emits the wide event when dropped.

Implements Deref<Target = WideEvent> so you can call setters directly.

let req = WideEventGuard::new("http");
req.set_str("method", "GET");
req.set_u64("status", 200);
// emitted automatically when `req` drops

Implementations§

Source§

impl WideEventGuard

Source

pub fn new(subsystem: &'static str) -> Self

Create a new guard that emits on drop.

Methods from Deref<Target = WideEvent>§

Source

pub fn set_emit_hook(&self, hook: EmitHook)

Set a hook called with the accumulated fields just before emit.

Source

pub fn has_key(&self, key: &str) -> bool

Returns true if the given key exists in the accumulated fields.

Source

pub fn set_str(&self, key: &'static str, val: &str)

Set a string field (copies val; use set_string to move an owned String).

Source

pub fn set_string(&self, key: &'static str, val: String)

Set a string field from an owned String (avoids a copy).

Source

pub fn set_i64(&self, key: &'static str, val: i64)

Set a signed 64-bit integer field.

Source

pub fn set_u64(&self, key: &'static str, val: u64)

Set an unsigned 64-bit integer field.

Source

pub fn set_f64(&self, key: &'static str, val: f64)

Set a 64-bit floating-point field (NaN / Inf are stored as null).

Source

pub fn set_bool(&self, key: &'static str, val: bool)

Set a boolean field.

Source

pub fn set_value(&self, key: &'static str, val: Value)

Set a field from a raw serde_json::Value.

Source

pub fn incr(&self, key: &'static str)

Increment an integer counter field by 1 (initialized to 1 if absent).

Source

pub fn set_error(&self, err_type: &str, message: &str)

Set error = true, error.type, and error.message.

Source

pub fn emit(&self)

Emit the wide event through the tracing pipeline.

The tracing target is {target_prefix}::{subsystem} where target_prefix defaults to wide_event. Configure the prefix on WideEventLayer::with_target_prefix.

Calling emit() more than once is a no-op.

Trait Implementations§

Source§

impl Deref for WideEventGuard

Source§

type Target = WideEvent

The resulting type after dereferencing.
Source§

fn deref(&self) -> &WideEvent

Dereferences the value.
Source§

impl Drop for WideEventGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more