1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//! Observability hooks for the [`StreamBus`](super::StreamBus) runtime.
//!
//! Without an observer the bus silently retries / backs off on transient
//! errors so steady-state traffic isn't poisoned by occasional failures.
//! Production deployments usually want those errors surfaced to metrics,
//! tracing, or alerting — that's what [`ErrorObserver`] is for.
//!
//! # Example
//!
//! ```rust,no_run
//! use std::sync::{Arc, atomic::{AtomicU64, Ordering}};
//! use eventbus_core::{EventBusError, ErrorScope, ErrorObserver};
//! use eventbus_core::stream::StreamBusOptions;
//!
//! struct Counter(AtomicU64);
//!
//! impl ErrorObserver for Counter {
//! fn on_error(&self, scope: ErrorScope, err: &EventBusError) {
//! eprintln!("[bus:{scope:?}] {err}");
//! self.0.fetch_add(1, Ordering::Relaxed);
//! }
//! }
//!
//! let opts = StreamBusOptions::default()
//! .with_error_observer(Arc::new(Counter(AtomicU64::new(0))));
//! ```
use crateEventBusError;
/// Where in the bus runtime an error was raised.
///
/// `#[non_exhaustive]` lets us add new sources without breaking observers.
/// Receives bus-level transient errors so they can be surfaced to metrics
/// or tracing.
///
/// Implementations **must not block** — the hook is called from inside the
/// consume / reclaim / ack loops. Push the event onto a queue or counter
/// and return.