corvix.observability.middleware

ASGI middleware recording per-request metrics, request IDs, and trace spans.

Sits outermost in the middleware stack so it observes every request (including auth failures), tags each one with a request_id bound into the logging context and echoed back in the X-Request-ID response header, and records request counts and latency by method, endpoint, and status.

Attributes

Classes

ObservabilityMiddleware

Record request metrics, bind a request ID, and open a trace span.

Functions

_endpoint_label(→ str)

Return a low-cardinality endpoint label from the matched route.

_request_id(→ str)

Module Contents

corvix.observability.middleware._REQUEST_ID_HEADER = b'x-request-id'[source][source]
corvix.observability.middleware._UNKNOWN_ENDPOINT = 'unknown'[source][source]
corvix.observability.middleware._endpoint_label(scope: litestar.types.asgi_types.Scope) str[source][source]

Return a low-cardinality endpoint label from the matched route.

Uses the registered path template (e.g. /api/v1/notifications/{account_id}/...) rather than the concrete path so per-ID paths do not explode label cardinality.

corvix.observability.middleware._request_id(scope: litestar.types.asgi_types.Scope) str[source][source]
class corvix.observability.middleware.ObservabilityMiddleware[source][source]

Bases: litestar.middleware.base.ASGIMiddleware

Record request metrics, bind a request ID, and open a trace span.

scopes[source][source]
async handle(scope: litestar.types.asgi_types.Scope, receive: litestar.types.asgi_types.Receive, send: litestar.types.asgi_types.Send, next_app: litestar.types.asgi_types.ASGIApp) None[source][source]

Wrap the downstream app with metrics, logging context, and a span.