Exemplar support
Adds exemplar support for the request counter and request latency histograms. This is intended to be used with tracing (e.g. OpenTelemetry).
You must supply your own callback function that returns a trace id to be used as the exemplar. PRs welcome with an example, or a simple OpenTelemetry-based helper function.
Example:
# must use `handle_openmetrics` instead of `handle_metrics` for exemplars to appear in /metrics output.
from starlette_exporter import PrometheusMiddleware, handle_openmetrics
app.add_middleware(
PrometheusMiddleware,
exemplars={"trace_id": get_trace_id} # supply your own callback function
)
app.add_route("/metrics", handle_openmetrics)
Exemplars are only supported by the openmetrics-text exposition format. A new handle_openmetrics handler function is provided (see above example).
For more information, see the Grafana exemplar documentation.