pub trait Subscribe:
Send
+ Sync
+ 'static {
// Required method
fn on_event(&self, event: &Event);
// Provided methods
fn name(&self) -> &'static str { ... }
fn queue_capacity(&self) -> usize { ... }
}Expand description
Event subscriber for runtime observability.
Each subscriber runs in isolation:
- Panic isolation: panics are caught and published as
SubscriberPanicked. - Bounded queue buffers events (capacity via
Self::queue_capacity). - Dedicated worker task processes events sequentially (FIFO).
§Implementation requirements
- Keep
on_eventfast: it runs on a dedicated worker task but blocks that worker’s event loop. For async I/O, send to a channel and process elsewhere. - Slow processing affects only this subscriber’s queue.
- Handle errors internally; do not panic.
§Synchronous design
on_event is intentionally synchronous:
- The
SubscriberSetinfrastructure already provides async fan-out via per-subscribermpscchannels and dedicated worker tasks. - If a subscriber needs async I/O, send events to a channel inside
on_eventand process them in a separate task. - Adding async to
on_eventwould force aBox::pinallocation per event per subscriber with no benefit; All real subscribers are synchronous.
§Also
Required Methods§
Provided Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Returns the subscriber name used in logs/metrics and overflow/panic events.
Prefer short, descriptive names (e.g., “metrics”, “audit”, “slack”).
The default uses type_name::<Self>(), which can be verbose - override it when possible.
Sourcefn queue_capacity(&self) -> usize
fn queue_capacity(&self) -> usize
Returns the preferred queue capacity for this subscriber.
Overflow behavior:
- The new event is dropped for this subscriber only,
- an
EventKind::SubscriberOverflowis published, - other subscribers are unaffected.
The runtime clamps capacity to a minimum of 1.
Default: 1024.