fastapi-observer
Zero-glue observability for FastAPI.
fastapi-observer gives you structured JSON logs, request correlation, Prometheus metrics, OpenTelemetry tracing, security redaction presets, and runtime controls in one install step and one function call.
Documentation: vitaee.github.io/FastapiObserver
Supported Python versions: 3.10 to 3.15
Compatibility Matrix
| Component | Supported / Tested |
|---|---|
| Python | 3.10 to 3.15 (CI matrix) |
| FastAPI | >=0.133.0 |
| Starlette | >=1.3.1 |
| pydantic-settings | >=2.10.1 |
| Prometheus backend | prometheus-client>=0.24.1 (optional extra) |
| OpenTelemetry | opentelemetry-api/sdk/exporter>=1.45.1 (optional extra) |
| Loguru bridge | loguru>=0.7.2 (optional extra) |
Why This Package Exists
Most FastAPI services eventually need the same observability plumbing:
- Structured JSON logging
- Request and trace correlation
- Metrics for dashboards and alerts
- OpenTelemetry setup
- Redaction/sanitization for sensitive data
- Runtime controls for incident response
Teams usually implement this as custom glue code in every service. That costs engineering time and creates drift between services.
fastapi-observer replaces this repeated wiring with a consistent, secure-by-default setup.
Sponsor
If this library saves you engineering time, you can support maintenance here:
What You Get Immediately
After one call to install_observability():
| Capability | Included | Default |
|---|---|---|
| Structured JSON logs | Yes | Enabled |
| Request ID correlation | Yes | Enabled |
| Trace/span IDs in logs | Yes (with OTel) | Off until OTel enabled |
Prometheus /metrics |
Yes | Off until metrics_enabled=True |
| Native FastAPI Lifespan | Yes | Explicit opt-in via observability_lifespan |
| Auto-discovery | Yes | Excluded routes (/docs, etc.) & DB engines |
| Sensitive-data redaction | Yes | Enabled |
Security presets (strict, pci, gdpr) |
Yes | Available |
| Runtime control endpoint | Yes | Off until enabled |
| Plugin hooks for enrichment/hooks | Yes | Available |
Install
# Core (logging + metrics + security)
pip install fastapi-observer
# Prometheus metrics support
pip install "fastapi-observer[prometheus]"
# Loguru coexistence bridge support
pip install "fastapi-observer[loguru]"
# OpenTelemetry tracing/logs support
pip install "fastapi-observer[otel]"
# Everything
pip install "fastapi-observer[all]"
Import path:
import fastapiobserver
5-Minute Quick Start ("Zero-Glue")
You can configure the entire library via environment variables simply by calling install_observability(app).
export APP_NAME="orders-api"
export SERVICE_NAME="orders"
export ENVIRONMENT="production"
export METRICS_ENABLED="true"
# Optional: Set a profile ("development" or "production") to auto-configure log levels, queues, and redaction strictness
export OBS_PROFILE="production"
from fastapi import FastAPI
from fastapiobserver import install_observability
app = FastAPI()
# Wires up logging, metrics, OTel, and security automatically from env vars
install_observability(app)
@app.get("/orders/{order_id}")
def get_order(order_id: int) -> dict[str, int]:
return {"order_id": order_id}
@app.get("/hidden", include_in_schema=False)
def hidden_endpoint():
# This endpoint is automatically excluded from
# Prometheus metrics and OTel tracing.
return {"status": "ok"}
Run:
uvicorn main:app --reload
Now you have:
- Structured request logs on every request
- Request ID propagation
- Sanitized event payloads (enforced by the
productionprofile) - Prometheus metrics at
/metrics
Environment Profiles (OBS_PROFILE)
To dramatically reduce boilerplate, you can use the OBS_PROFILE environment variable to automatically set sensible defaults for your environment:
OBS_PROFILE=development: ForcesLOG_LEVEL=DEBUGand disables any OpenTelemetry network overhead to keep local development fast and noisy.OBS_PROFILE=production: ForcesLOG_LEVEL=INFO, optimizes internal queues for massive throughput (LOG_QUEUE_MAX_SIZE=20000), and enforces thestrictsecurity redaction preset.
(Explicit env vars or Python arguments will always override profile defaults).
Documentation Map
Full documentation lives at vitaee.github.io/FastapiObserver. Deep dives:
- Security & Presets
- Environment Variables
- Runtime Control
- OpenTelemetry
- Logtail Sink
- Audit Logging
- Database Tracing
- GraphQL Support
- Architecture & Operations
- Production Deployment
- Performance Tuning
- Advanced Operations
- Maintenance & Contributing (quality gates, release flow, runtime stress harness)
Metadata
Release files for fastapi-observer 1.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_observer-1.4.1.tar.gz | 94.9 kB | With provenance | Details for fastapi_observer-1.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_observer-1.4.1-py3-none-any.whl | Python 3 | none | any | Details for fastapi_observer-1.4.1-py3-none-any.whl |
Total release size: 182.1 kB
Release files / fastapi_observer-1.4.1.tar.gz
| Download URL | fastapi_observer-1.4.1.tar.gz |
|---|---|
| Size | 94.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
99522d63f16472e54de7fa779c62f501f3bd7a5e0ad68c6cedfe37090c0a7a59
|
|
BLAKE2b-256 checksum How to use checksums |
61b9ad7d06282cf0ddfa87d130151d382e57603410302c9f33d884f23d11a720
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logRelease files / fastapi_observer-1.4.1-py3-none-any.whl
| Download URL | fastapi_observer-1.4.1-py3-none-any.whl |
|---|---|
| Size | 87.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c5b313e1a62fcc4e31d87243b60bd4b60bac14a294fd5d44a43daab466bcf81
|
|
BLAKE2b-256 checksum How to use checksums |
5305da77114efeb516a17eb44aa6e482670e3794726dc84dd1bffcbb981aeb51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logSecurity for fastapi-observer 1.4.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for fastapi_observer-1.4.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logA 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.