Skip to main content

PoolListener

Trait PoolListener 

Source
pub trait PoolListener<T>: Send + Sync {
    // Provided methods
    fn on_connection_created(&self, _conn: &PooledConnection<T>, _duration: f64) { ... }
    fn on_connection_closed(
        &self,
        _conn: &PooledConnection<T>,
        _reason: CloseReason,
    ) { ... }
    fn on_create_failed(&self, _error: &(dyn Error + 'static)) { ... }
    fn on_acquired(&self, _conn: &PooledConnection<T>, _wait_time: f64) { ... }
    fn on_released(&self, _conn: &PooledConnection<T>, _hold_time: f64) { ... }
    fn on_acquire_timeout(&self, _waited: f64) { ... }
    fn on_connection_leak(&self, _conn: &PooledConnection<T>, _held_for: f64) { ... }
    fn on_breaker_state_change(&self, _old: BreakerState, _new: BreakerState) { ... }
}
Expand description

Observability hooks for metrics, tracing, logging. Implement the ones you care about; all default to no-ops. Hooks run synchronously on the calling thread, outside the pool’s lock, so keep them fast. Panics raised by a listener are caught and logged — a broken metrics exporter must never break the pool.

Provided Methods§

Source

fn on_connection_created(&self, _conn: &PooledConnection<T>, _duration: f64)

A new connection was created and registered.

Source

fn on_connection_closed( &self, _conn: &PooledConnection<T>, _reason: CloseReason, )

A connection was closed, with the reason it left the pool.

Source

fn on_create_failed(&self, _error: &(dyn Error + 'static))

A create attempt failed (fires per attempt inside the retry loop).

Source

fn on_acquired(&self, _conn: &PooledConnection<T>, _wait_time: f64)

A connection was acquired, with how long the caller waited.

Source

fn on_released(&self, _conn: &PooledConnection<T>, _hold_time: f64)

A connection was released, with how long it was held.

Source

fn on_acquire_timeout(&self, _waited: f64)

An acquire timed out, with how long the caller waited.

Source

fn on_connection_leak(&self, _conn: &PooledConnection<T>, _held_for: f64)

A borrowed connection was flagged as possibly leaked (held too long).

Source

fn on_breaker_state_change(&self, _old: BreakerState, _new: BreakerState)

The circuit breaker changed state.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§