pub async fn trace_requests(req: Request, next: Next) -> ResponseExpand description
Axum middleware that emits a structured tracing event when each request completes.
The info-level event records method, path, status, latency_ms, and request_id
(the latter when propagate_request_id runs earlier in the stack). With no tracing
subscriber installed the event is a no-op. Requires the trace feature.
ยงExample
use axum::{middleware, routing::get, Router};
use axum_api_kit::{propagate_request_id, trace_requests};
// The last `.layer` is the outermost: request ids are assigned before the trace event
// is recorded, so the event can include them.
let app: Router = Router::new()
.route("/", get(|| async { "ok" }))
.layer(middleware::from_fn(trace_requests))
.layer(middleware::from_fn(propagate_request_id));