SummaryEmitter

Struct SummaryEmitter 

Source
pub struct SummaryEmitter<S>{ /* private fields */ }
Expand description

Emits periodic summaries of suppressed events.

Implementations§

Source§

impl<S> SummaryEmitter<S>

Source

pub fn new(registry: SuppressionRegistry<S>, config: EmitterConfig) -> Self

Create a new summary emitter.

Source

pub fn collect_summaries(&self) -> Vec<SuppressionSummary>

Collect current suppression summaries.

Returns summaries for all events that have been suppressed at least min_count times.

Source

pub fn start<F>(self, emit_fn: F, emit_final: bool) -> EmitterHandle
where F: FnMut(Vec<SuppressionSummary>) + Send + 'static, S: Send + 'static,

Start emitting summaries periodically (async version).

This spawns a background task that emits summaries at the configured interval. The task will run until shutdown() is called on the returned EmitterHandle.

§Graceful Shutdown

When shutdown() is called on the EmitterHandle:

  1. The shutdown signal is prioritized over tick events
  2. The current emission completes if in progress
  3. If emit_final is true, one final emission occurs with current summaries
  4. The background task completes gracefully
§Cancellation Safety

The spawned task is cancellation-safe:

  • collect_summaries() reads atomically from storage without mutations
  • If cancelled during emission, the next startup will see correct state
  • Panics in emit_fn are caught and don’t abort the task
  • The emit_fn closure should be cancellation-safe (avoid holding locks across .await)
§Type Parameters
  • F - The emission function. Must be Send + 'static because it runs in a spawned task that may execute on any thread in the tokio runtime. The function receives ownership of the summaries vector.
§Examples
let emitter = SummaryEmitter::new(registry, config);
let handle = emitter.start(|summaries| {
    for summary in summaries {
        tracing::warn!("{}", summary.format_message());
    }
}, true);

// Later, trigger graceful shutdown
handle.shutdown().await.expect("shutdown failed");
Source

pub fn config(&self) -> &EmitterConfig

Get the emitter configuration.

Source

pub fn registry(&self) -> &SuppressionRegistry<S>

Get a reference to the registry.

Auto Trait Implementations§

§

impl<S> Freeze for SummaryEmitter<S>
where S: Freeze,

§

impl<S> !RefUnwindSafe for SummaryEmitter<S>

§

impl<S> Send for SummaryEmitter<S>

§

impl<S> Sync for SummaryEmitter<S>

§

impl<S> Unpin for SummaryEmitter<S>
where S: Unpin,

§

impl<S> !UnwindSafe for SummaryEmitter<S>

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<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