prometheus¶
- class litestar.plugins.prometheus.PrometheusConfig[source]¶
Bases:
objectConfiguration class for the PrometheusConfig middleware.
- labels: Mapping[str, str | Callable] | None = None¶
A mapping of labels to add to the metrics. The values can be either a string or a callable that returns a string.
- exemplars: Callable[[Request], dict] | None = None¶
A callable that returns a list of exemplars to add to the metrics. Only supported in opementrics-text exposition format.
- excluded_http_methods: Method | Sequence[Method] | None = None¶
A list of http methods to exclude from the metrics.
- __init__(app_name: str = 'litestar', prefix: str = 'litestar', labels: Mapping[str, str | Callable] | None = None, exemplars: Callable[[Request], dict] | None = None, buckets: Sequence[str | float] | None = None, excluded_http_methods: Method | Sequence[Method] | None = None, exclude_unhandled_paths: bool = False, exclude: str | list[str] | None = None, exclude_opt_key: str | None = None, scopes: Scopes | None = None, middleware_class: type[PrometheusMiddleware] = <class 'litestar.plugins.prometheus.middleware.PrometheusMiddleware'>, group_path: bool = True) None¶
- exclude_unhandled_paths: bool = False¶
Whether to ignore requests for unhandled paths from the metrics.
- exclude: str | list[str] | None = None¶
A pattern or list of patterns for routes to exclude from the metrics.
- exclude_opt_key: str | None = None¶
A key or list of keys in
optwith which a route handler can “opt-out” of the middleware.
- scopes: Scopes | None = None¶
ASGI scopes processed by the middleware, if None both
httpandwebsocketwill be processed.
- middleware_class¶
alias of
PrometheusMiddleware
- property middleware: DefineMiddleware¶
Create an instance of
DefineMiddlewarethat wraps with.[PrometheusMiddleware][litestar.plugins.prometheus.PrometheusMiddleware]. or a subclass of this middleware.
- Returns:
An instance of
DefineMiddleware.
- class litestar.plugins.prometheus.PrometheusController[source]¶
Bases:
ControllerController for Prometheus endpoints.
- after_request¶
A sync or async function executed before a
Requestis passed to any route handler.If this function returns a value, the request will not reach the route handler, and instead this value will be used.
- after_response¶
A sync or async function called after the response has been awaited.
It receives the
Requestinstance and should not return any values.
- before_request¶
A sync or async function called immediately before calling the route handler.
It receives the
Requestinstance and any non-Nonereturn value is used for the response, bypassing the route handler.
- cache_control¶
A
CacheControlHeaderheader to add to route handlers of this controller.Can be overridden by route handlers.
- dto¶
AbstractDTOto use for (de)serializing and validation of request data.
- etag¶
An
etagheader of typeETagto add to route handlers of this controller.Can be overridden by route handlers.
- exception_handlers¶
A map of handler functions to status codes and/or exception types.
- include_in_schema¶
A boolean flag dictating whether the route handler should be documented in the OpenAPI schema
- middleware¶
A sequence of
Middleware.
- opt¶
A string key mapping of arbitrary values that can be accessed in
Guardsor wherever you have access toRequestorASGI Scope.
- request_class¶
A custom subclass of
Requestto be used as the default request for all route handlers under the controller.
- request_max_body_size¶
Maximum allowed size of the request body in bytes. If this size is exceeded, a ‘413 - Request Entity Too Large’ error response is returned.
- response_class¶
A custom subclass of
Responseto be used as the default response for all route handlers under the controller.
- response_headers¶
A string keyed dictionary mapping
ResponseHeaderinstances.
- return_dto¶
AbstractDTOto use for serializing outbound response data.
- security¶
A sequence of dictionaries that to the schema of all route handlers under the controller.
- signature_namespace¶
A mapping of names to types for use in forward reference resolution during signature modelling.
- signature_types¶
A sequence of types for use in forward reference resolution during signature modelling.
These types will be added to the signature namespace using their
__name__attribute.
- tags¶
A sequence of string tags that will be appended to the schema of all route handlers under the controller.
- type_decoders¶
A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.
- type_encoders¶
A mapping of types to callables that transform them into types supported for serialization.
- class litestar.plugins.prometheus.PrometheusMiddleware[source]¶
Bases:
AbstractMiddlewarePrometheus Middleware.
- __init__(app: ASGIApp, config: PrometheusConfig) None[source]¶
Middleware that adds Prometheus instrumentation to the application.
- Parameters:
app¶ – The
nextASGI app to call.config¶ – An instance of
PrometheusConfig