// the find
trallnag/prometheus-fastapi-instrumentator
Instrument your FastAPI with Prometheus metrics.
A middleware library that bolts Prometheus metrics onto a FastAPI app with one or two lines of setup. It's for anyone who wants request count, latency, and size metrics scraped by Prometheus without hand-rolling the client library calls themselves.
The closure-based metrics system is genuinely well designed — each metric is a self-contained factory function you can configure and pass to `add()`, so extending it doesn't mean forking the library. The defaults are sensible for production: status codes get grouped to keep cardinality down, and it ships two duration histograms (coarse buckets for alerting, high-res for p99 digging) instead of making you choose one. The README's disclaimer section is unusually honest — it tells you outright this isn't a general-purpose Prometheus wrapper and that the middleware has a real performance cost, rather than pretending it's free.
Exceptions thrown inside route handlers aren't caught by the instrumentator, which the docs admit but bury — if your handler errors out, the response object in `Info` can be `None` and your custom metric closures need to handle that explicitly or they'll throw. Multi-process deployments (gunicorn/uvicorn workers) need the `prometheus_client` multiproc env var dance, which is only covered in a `devel/examples` folder rather than being a first-class configuration option. The `routing` module is BSD-3 licensed separately from the rest of the ISC-licensed codebase (inherited from elastic/apm-agent-python), which is a minor but real thing to flag if your org does license scanning.