Skip to main content

Module api_error_middleware

Module api_error_middleware 

Source
Expand description

Reusable axum middleware that emits TelemetryEvent::ApiError on every HTTP response with status >= 400. Mounts on any axum router an agent crate exposes (status-server dashboard, MCP HTTP front-end, etc.).

Agent-side events omit operator_principal — agent dashboards are typically loopback-bound and not authenticated as operators. Orchestrators emitting the mirror event populate the principal field from their own auth layer.

Structs§

ApiErrorTelemetry
Bundle the emitter and a reusable TelemetryContext so the middleware can build the event without per-request context lookups. Status-server-style routes are non-task-scoped, so the context’s job_id / round / phase are None.

Functions§

api_error_telemetry_middleware
Middleware entry point. Mount via axum::middleware::from_fn_with_state. The state is a Option<Arc<ApiErrorTelemetry>> so callers can pass None to disable the layer at config time without a separate router shape.