pub struct SummaryEmitter<S>{ /* private fields */ }Expand description
Emits periodic summaries of suppressed events.
Implementations§
Source§impl<S> SummaryEmitter<S>
impl<S> SummaryEmitter<S>
Sourcepub fn new(registry: SuppressionRegistry<S>, config: EmitterConfig) -> Self
pub fn new(registry: SuppressionRegistry<S>, config: EmitterConfig) -> Self
Create a new summary emitter.
Sourcepub fn collect_summaries(&self) -> Vec<SuppressionSummary>
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.
Sourcepub fn start<F>(self, emit_fn: F, emit_final: bool) -> EmitterHandle
pub fn start<F>(self, emit_fn: F, emit_final: bool) -> EmitterHandle
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:
- The shutdown signal is prioritized over tick events
- The current emission completes if in progress
- If
emit_finalis true, one final emission occurs with current summaries - 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_fnare caught and don’t abort the task - The
emit_fnclosure should be cancellation-safe (avoid holding locks across.await)
§Type Parameters
F- The emission function. Must beSend + 'staticbecause 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");Sourcepub fn config(&self) -> &EmitterConfig
pub fn config(&self) -> &EmitterConfig
Get the emitter configuration.
Sourcepub fn registry(&self) -> &SuppressionRegistry<S>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more