Skip to main content

Observer

Trait Observer 

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

Source

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.

Source

fn record_metric(&self, metric: &ObserverMetric)

Record a numeric metric sample.

Called synchronously; same non-blocking guidance as record_event.

Source

fn name(&self) -> &str

Return the human-readable name of this observer backend.

Used in logs and diagnostics (e.g., "console", "prometheus", "opentelemetry").

Source

fn as_any(&self) -> &dyn Any

Downcast to Any for backend-specific operations.

Enables callers to access concrete observer types when needed (e.g., retrieving a Prometheus registry handle for custom metrics).

Provided Methods§

Source

fn flush(&self)

Flush any buffered telemetry data to the backend.

The runtime calls this during graceful shutdown. The default implementation is a no-op, which is appropriate for backends that write synchronously.

Implementors§