Prax provides a powerful middleware system for intercepting queries before and after execution. Use middleware for logging, metrics, authentication, caching, retry logic, and more.
The middleware system allows you to intercept every query before and after execution. Middleware can modify queries, add context, collect metrics, implement caching, and more.
LoggingMiddleware - Query logging with levelsMetricsMiddleware - Performance metricsTimingMiddleware - Execution time trackingRetryMiddleware - Automatic retry with backoffLog all queries with configurable detail levels. Automatically detect slow queries and log warnings.
| Level | Description |
|---|---|
Off |
No logging |
Error |
Only errors |
Warn |
Errors and slow queries |
Info |
All queries (default) |
Debug |
Queries with parameters |
Trace |
Everything including responses |
Collect query performance metrics for monitoring and optimization.
total_queries
Total query count
successful_queries
Successful count
failed_queries
Failed count
avg_time_us
Average time (μs)
slow_queries
Slow query count
cache_hits
Cache hit count
Automatically retry failed queries with exponential backoff. Perfect for handling transient errors.
Create your own middleware by implementing the Middleware trait.
The QueryContext provides information about the current query and allows modification.