Skip to main content

fastapi-observer

CI Sponsor

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.11 and newer (CI-tested on 3.11 to 3.15)


Compatibility Matrix

Component Supported / Tested
Python >=3.11 (CI matrix: 3.11 to 3.15)
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:

buymeacoffee.com/FYbPCSu


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 production profile)
  • 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: Forces LOG_LEVEL=DEBUG and disables any OpenTelemetry network overhead to keep local development fast and noisy.
  • OBS_PROFILE=production: Forces LOG_LEVEL=INFO, optimizes internal queues for massive throughput (LOG_QUEUE_MAX_SIZE=20000), and enforces the strict security 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:

Metadata

Release files for fastapi-observer 1.5.0

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-observer 1.5.0
File Size Uploaded Provenance Actions
fastapi_observer-1.5.0.tar.gz 96.5 kB With provenance Details for fastapi_observer-1.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-observer 1.5.0
File Interpreter ABI Platform Actions
fastapi_observer-1.5.0-py3-none-any.whl Python 3 none any Details for fastapi_observer-1.5.0-py3-none-any.whl

Total release size: 184.9 kB

Release files / fastapi_observer-1.5.0.tar.gz

Download URL fastapi_observer-1.5.0.tar.gz
Size 96.5 kB
Tags Source
SHA-256 checksum
How to use checksums
050cd1e79b15382ccb2bdaba5c254f22810898bf88905f0ce915e5d83609945b
BLAKE2b-256 checksum
How to use checksums
f8c46dfdb8b7e55ac19f38a891db9f8f925d5854dc3c5ccac42fb4bd0322a5fd
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 31, 2026.

Transparency log

Release files / fastapi_observer-1.5.0-py3-none-any.whl

Download URL fastapi_observer-1.5.0-py3-none-any.whl
Size 88.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f48527cc5f67d94f4a3c5b11c43d6c76475e69f8cb9be9441ae922b4a728607d
BLAKE2b-256 checksum
How to use checksums
2d9b906aa24c9304004e5e948c41ab348861c5f138847c80a556d5a5fffa4cba
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 31, 2026.

Transparency log

Security for fastapi-observer 1.5.0

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.

Select from 2 files

Attestation for fastapi_observer-1.5.0.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 31, 2026.

Transparency log

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

1.5.0 This release

2 release files Full 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