Skip to main content

fastapi-telemetry

📢 Hobby Project Notice: This is a research and learning project exploring FastAPI observability and Prometheus metrics best practices. Feel free to use it as a reference, report issues, or suggest improvements! Contributions and feedback are always welcome.

Prometheus metrics middleware, circuit breaker listener, and metric helpers for FastAPI — zero project-specific dependencies (only Starlette and prometheus-client).

Features

  • PrometheusMiddleware — HTTP request duration, count, and in-flight metrics out of the box via injectable callbacks (no coupling to a specific metrics facade)
  • CircuitBreakerMetricsListener — pybreaker listener that exports circuit breaker state, state-changes, and failure counts to Prometheus (optional dependency)
  • get_or_create_counter / get_or_create_gauge / get_or_create_histogram — safe helpers that return an existing metric from the registry instead of raising ValueError on duplicate registration (useful with --reload)

Installation

# Core (middleware + helpers)
pip install fastapi-telemetry

# With circuit-breaker support
pip install "fastapi-telemetry[circuit-breaker]"

Quick start

from fastapi import FastAPI
from fastapi_telemetry import PrometheusMiddleware, CircuitBreakerMetricsListener
from prometheus_client import make_asgi_app

app = FastAPI()

# Mount Prometheus scrape endpoint
app.mount("/metrics", make_asgi_app())

# Wire up the middleware with your own metric callbacks
app.add_middleware(
    PrometheusMiddleware,
    request_start_callback=lambda method, path: None,   # replace with your gauge.inc()
    request_end_callback=lambda m, p, s, d: None,       # replace with your histogram
    error_callback=lambda error_type, path: None,       # replace with your counter.inc()
)

Circuit breaker

from pybreaker import CircuitBreaker
from fastapi_telemetry import CircuitBreakerMetricsListener

cb = CircuitBreaker(
    name="redis",
    listeners=[CircuitBreakerMetricsListener(service_name="redis")],
)

License

MIT

Metadata

Release files for fastapi-telemetry 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-telemetry 0.0.2
File Size Uploaded Provenance Actions
fastapi_telemetry-0.0.2.tar.gz 49.1 kB Without provenance Details for fastapi_telemetry-0.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-telemetry 0.0.2
File Interpreter ABI Platform Actions
fastapi_telemetry-0.0.2-py3-none-any.whl Python 3 none any Details for fastapi_telemetry-0.0.2-py3-none-any.whl

Total release size: 55.8 kB

Release files / fastapi_telemetry-0.0.2.tar.gz

Download URL fastapi_telemetry-0.0.2.tar.gz
Size 49.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dcc2a32c81e1cf853b81f8e4fbca85e64ff6be4138bb0214d83ddbce1e8f628e
BLAKE2b-256 checksum
How to use checksums
0a4de39174532ecdd58483c2563c9e369d98707e49e2665723ed402616f4ae93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"openSUSE Tumbleweed","version":"20260223","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / fastapi_telemetry-0.0.2-py3-none-any.whl

Download URL fastapi_telemetry-0.0.2-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c125a676b8bb3fefcbaceb3594bf81c09b061cf9c265c7e577fae4abfde88d15
BLAKE2b-256 checksum
How to use checksums
894bb7ed36080889f106cde8c4b17abeb6ee7482fa29a12fba03fc0b6d91b5a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"openSUSE Tumbleweed","version":"20260223","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for fastapi-telemetry 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page