A configurable and modular Prometheus instrumentator for FastAPI applications to expose metrics.
Prometheus FastAPI Instrumentator is a Python library that adds Prometheus metrics collection to FastAPI applications. It automatically instruments HTTP endpoints to expose metrics like request counts, latencies, and sizes, solving the problem of manual metric setup for monitoring and observability.
Developers building FastAPI applications who need production-ready monitoring with Prometheus, especially those in DevOps or SRE roles focused on observability.
It offers a highly configurable and modular approach out-of-the-box, with sensible defaults and the flexibility to add custom metrics, making it easier than using the raw Prometheus client library directly.
Instrument your FastAPI with Prometheus metrics.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Allows regex-based route ignoring, environment variable control for instrumentation, and custom label configuration, as detailed in the 'Advanced Usage' section with options like should_ignore_untemplated and excluded_handlers.
Supports selecting from pre-built metrics (e.g., latency, request_size) or creating custom ones via closures, enabling tailored monitoring without boilerplate code, as shown in the 'Adding metrics' and 'Creating new metrics' examples.
Includes sensible defaults like grouped status codes and low-cardinality histograms to balance detail with performance, and offers gzip compression for the metrics endpoint to reduce network bandwidth, mentioned in the 'Features' and 'Exposing endpoint' sections.
Provides a fast track with minimal code (Instrumentator().instrument(app).expose(app)) to get started with default HTTP metrics like request counts and latencies, making it accessible for basic use cases.
The README explicitly warns that generic middleware and instrumentation code introduce a performance cost that can become noticeable, potentially impacting request latency in high-traffic applications.
Only works with FastAPI; it cannot be used for other Python web frameworks, limiting its utility in polyglot or multi-framework environments without additional integration effort.
Creating new metrics requires understanding closures and the Info object, and the README notes that error handling in custom functions is not automatic, advising developers to check the source code for nuances.