Skip to main content

QueryMonitor

Trait QueryMonitor 

Source
pub trait QueryMonitor: Send + Sync {
    // Required method
    fn on_query_complete(
        &self,
        ctx: &QueryContext,
        duration: Duration,
        result: &QueryResult,
    );

    // Provided methods
    fn on_query_start(&self, _ctx: &QueryContext) { ... }
    fn on_slow_query(&self, _ctx: &QueryContext, _duration: Duration) { ... }
}
Expand description

Trait for monitoring SQL query execution.

Implement this trait to collect metrics, log queries, or integrate with observability systems.

Required Methods§

Source

fn on_query_complete( &self, ctx: &QueryContext, duration: Duration, result: &QueryResult, )

Called after a query completes (success or failure).

§Arguments
  • ctx - Query context information
  • duration - Time taken to execute the query
  • result - The result of the query

Provided Methods§

Source

fn on_query_start(&self, _ctx: &QueryContext)

Called before a query is executed.

Default implementation does nothing.

Source

fn on_slow_query(&self, _ctx: &QueryContext, _duration: Duration)

Called when a slow query is detected.

Default implementation does nothing. Override to add alerting.

Implementors§