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§
Sourcefn on_connection_created(&self, _conn: &PooledConnection<T>, _duration: f64)
fn on_connection_created(&self, _conn: &PooledConnection<T>, _duration: f64)
A new connection was created and registered.
Sourcefn on_connection_closed(
&self,
_conn: &PooledConnection<T>,
_reason: CloseReason,
)
fn on_connection_closed( &self, _conn: &PooledConnection<T>, _reason: CloseReason, )
A connection was closed, with the reason it left the pool.
Sourcefn on_create_failed(&self, _error: &(dyn Error + 'static))
fn on_create_failed(&self, _error: &(dyn Error + 'static))
A create attempt failed (fires per attempt inside the retry loop).
Sourcefn on_acquired(&self, _conn: &PooledConnection<T>, _wait_time: f64)
fn on_acquired(&self, _conn: &PooledConnection<T>, _wait_time: f64)
A connection was acquired, with how long the caller waited.
Sourcefn on_released(&self, _conn: &PooledConnection<T>, _hold_time: f64)
fn on_released(&self, _conn: &PooledConnection<T>, _hold_time: f64)
A connection was released, with how long it was held.
Sourcefn on_acquire_timeout(&self, _waited: f64)
fn on_acquire_timeout(&self, _waited: f64)
An acquire timed out, with how long the caller waited.
Sourcefn on_connection_leak(&self, _conn: &PooledConnection<T>, _held_for: f64)
fn on_connection_leak(&self, _conn: &PooledConnection<T>, _held_for: f64)
A borrowed connection was flagged as possibly leaked (held too long).
Sourcefn on_breaker_state_change(&self, _old: BreakerState, _new: BreakerState)
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".