pub trait Observer:
Send
+ Sync
+ 'static {
// Required methods
fn record_event(&self, event: &ObserverEvent);
fn record_metric(&self, metric: &ObserverMetric);
fn name(&self) -> &str;
fn as_any(&self) -> &dyn Any;
// Provided method
fn flush(&self) { ... }
}Expand description
Core observability trait for recording agent runtime telemetry.
Implement this trait to integrate with any monitoring backend (structured
logging, Prometheus, OpenTelemetry, etc.). The agent runtime holds one or
more Observer instances and calls record_event
and record_metric at key lifecycle points.
Implementations must be Send + Sync + 'static because the observer is
shared across async tasks via Arc.
Required Methods§
Sourcefn record_event(&self, event: &ObserverEvent)
fn record_event(&self, event: &ObserverEvent)
Record a discrete lifecycle event.
Called synchronously on the hot path; implementations should avoid blocking I/O. Buffer events internally and flush asynchronously when possible.
Sourcefn record_metric(&self, metric: &ObserverMetric)
fn record_metric(&self, metric: &ObserverMetric)
Record a numeric metric sample.
Called synchronously; same non-blocking guidance as
record_event.
Provided Methods§
Implementations on Foreign Types§
Source§impl<T: Observer + ?Sized> Observer for Arc<T>
Blanket implementation: Arc<T> delegates all Observer methods to T.
impl<T: Observer + ?Sized> Observer for Arc<T>
Blanket implementation: Arc<T> delegates all Observer methods to T.
Lets a singleton observer be handed out as Arc<MyObserver> and still be
used wherever Box<dyn Observer> is expected (e.g.
Box::new(MyObserver::shared())). as_any deliberately delegates to the
inner T so downcasts in handlers like /metrics recover the concrete
type rather than the Arc wrapper.