Skip to main content

Metrics

Trait Metrics 

Source
pub trait Metrics:
    Send
    + Sync
    + 'static {
    // Provided methods
    fn on_request(&self, _method: &str) { ... }
    fn on_response(&self, _method: &str) { ... }
    fn on_error(&self, _method: &str, _error: &str) { ... }
    fn on_latency(&self, _method: &str, _duration: Duration) { ... }
    fn on_queue_depth_change(&self, _active_queues: usize) { ... }
    fn on_connection_pool_stats(&self, _stats: &ConnectionPoolStats) { ... }
}
Expand description

Trait for receiving metrics callbacks from the handler.

All methods have default no-op implementations so that consumers can override only the callbacks they care about.

Provided Methods§

Source

fn on_request(&self, _method: &str)

Called when a request is received, before processing.

Source

fn on_response(&self, _method: &str)

Called when a response is successfully sent.

Source

fn on_error(&self, _method: &str, _error: &str)

Called when a request results in an error.

Source

fn on_latency(&self, _method: &str, _duration: Duration)

Called when a request completes (successfully or not) with the wall-clock duration from receipt to response.

This is the #1 production observability metric — use it to feed histograms, percentile trackers, or SLO dashboards.

Source

fn on_queue_depth_change(&self, _active_queues: usize)

Called when the number of active event queues changes.

Source

fn on_connection_pool_stats(&self, _stats: &ConnectionPoolStats)

Called with connection pool statistics when available.

Useful for monitoring connection pool health and detecting exhaustion.

Implementations on Foreign Types§

Source§

impl<T: Metrics + ?Sized> Metrics for Arc<T>

Blanket implementation: Arc<T> implements Metrics if T does.

This eliminates the need for wrapper types like MetricsForward when sharing a metrics instance across multiple handlers or tasks.

Source§

fn on_request(&self, method: &str)

Source§

fn on_response(&self, method: &str)

Source§

fn on_error(&self, method: &str, error: &str)

Source§

fn on_latency(&self, method: &str, duration: Duration)

Source§

fn on_queue_depth_change(&self, active_queues: usize)

Source§

fn on_connection_pool_stats(&self, stats: &ConnectionPoolStats)

Implementors§