DEV.co
Open-Source Observability · blueswen

fastapi-observability

FastAPI Observability is a reference implementation demonstrating how to integrate FastAPI applications with the three pillars of observability: distributed tracing (Tempo), metrics (Prometheus), and logs (Loki), all visualized through Grafana. It provides production-ready patterns for trace ID correlation across services and exemplar-based navigation between signals.

Source: GitHub — github.com/blueswen/fastapi-observability
1.1k
GitHub stars
139
Forks
Python
Primary language
MIT
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryblueswen/fastapi-observability
Ownerblueswen
Primary languagePython
LicenseMIT — OSI-approved
Stars1.1k
Forks139
Open issues6
Latest releaseUnknown
Last updated2026-04-12
Sourcehttps://github.com/blueswen/fastapi-observability

What fastapi-observability is

The project provides Docker Compose configuration and Python instrumentation code leveraging OpenTelemetry SDK to emit traces via gRPC to Tempo, Prometheus Python Client for metrics with exemplars, and LoggingInstrumentor for trace-ID-enriched logs. It demonstrates cross-service span propagation, metric-to-trace correlation via exemplars, and Grafana dashboard configuration for unified observability.

Quickstart

Get the fastapi-observability source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/blueswen/fastapi-observability.gitcd fastapi-observability# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Microservices Debugging and Distributed Tracing

Teams operating FastAPI microservices can use this as a template to correlate requests across service boundaries. The span injection example shows how to propagate trace IDs through HTTP headers, enabling root-cause analysis of failures in multi-service workflows.

Production Observability Stack Setup

Organizations adopting Grafana, Tempo, Prometheus, and Loki can leverage the Docker Compose configuration and instrumentation patterns as a blueprint for standardized FastAPI observability. Reduces onboarding time for developers integrating new services.

SLA/Performance Monitoring with Correlation

Use the exemplar-based metric-to-trace navigation to investigate latency anomalies. The dashboard configuration and query examples enable teams to move from alerting on metrics to detailed trace inspection without switching contexts.

Implementation considerations

  • Loki Docker Driver installation is a prerequisite; verify ARM64 vs AMD64 compatibility and enable plugin after install.
  • Trace ID must be manually injected into outbound HTTP headers via `inject()` or instrumented via the HTTPXClientInstrumentor; automatic propagation is not guaranteed across all client libraries.
  • The FastAPIInstrumentor generates child spans for internal ASGI interactions, which may inflate trace size; mitigation requires custom middleware as documented in the referenced issue #831.
  • Log format override uses `LoggingInstrumentor` set_logging_format=True; verify compatibility with existing Python logging configuration and handlers in your application.
  • gRPC endpoint for OTLP must be reachable from application containers; network policy and DNS resolution should be validated in production deployments.

When to avoid it — and what to weigh

  • Serverless or Event-Driven Architecture Dominance — The project assumes always-on services with direct HTTP communication. Serverless functions, async message queues, and ephemeral workloads require adapted instrumentation patterns not covered here.
  • Non-Python Application Stack — The instrumentation code is Python-specific (OpenTelemetry Python SDK, Prometheus client). Multi-language environments require separate implementation per language.
  • Lightweight, Zero-Setup Observability Requirement — This stack requires running and maintaining five additional services (Grafana, Tempo, Prometheus, Loki, plus log driver). Teams seeking minimal infrastructure overhead should consider managed SaaS alternatives.
  • Strict Resource Constraints on Edge/IoT — The OpenTelemetry SDK and gRPC exporters add runtime overhead. Batch span processing helps but does not eliminate the footprint—unsuitable for severely resource-constrained environments.

License & commercial use

MIT License. Permissive OSI-approved license allowing commercial use, modification, and distribution with no warranty.

MIT license permits commercial use without royalties or restrictions. However, the project is a reference implementation and code example, not a supported product. Commercial deployment should involve internal testing, customization, and support plan for the observability stack itself (Grafana, Prometheus, Tempo, Loki versions and security patches).

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityModerate
DEV.co fitGood
Assessment confidenceHigh
Security considerations

Observability stack handles sensitive operational data (traces, logs, metrics). No security hardening guidance provided in documentation. Consider: gRPC transport encryption for OTLP exporter, Grafana authentication/RBAC, Loki data retention policies, log scrubbing for PII in traces/logs, and network isolation between app and observability backend. Default docker-compose credentials (admin:admin) must not be used in production.

Alternatives to consider

Datadog APM + Log Management

Fully managed SaaS with native FastAPI instrumentation, automatic trace correlation, and reduced operational overhead. Suitable if vendor lock-in and ongoing costs are acceptable.

New Relic One + OpenTelemetry

Managed backend supporting OTLP export; eliminates need to run Tempo, Prometheus, Loki. Trade-off: SaaS pricing and less control over data storage.

Jaeger (OSS alternative to Tempo)

Alternative tracing backend with similar API. May integrate with Prometheus/Loki, but ecosystem integration and Grafana native support is stronger for Tempo.

Software development agency

Build on fastapi-observability with DEV.co software developers

We help DevOps and engineering teams design and deploy scalable observability stacks. Let's discuss your tracing, metrics, and logging strategy.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

fastapi-observability FAQ

Can I use this without Loki?
Yes. The traces (Tempo) and metrics (Prometheus) components are independent. Loki is optional if logs are not a priority, but Grafana dashboards expect all three for full functionality.
How do I propagate trace IDs to external HTTP services?
Use the `inject()` function from opentelemetry.propagate to add trace context to HTTP headers before making requests. Alternatively, instrument your HTTP client (e.g., HTTPXClientInstrumentor) to automate injection.
What happens if the Tempo gRPC endpoint is unreachable?
Spans are buffered in the BatchSpanProcessor. Depending on batch timeout and queue size, spans may be dropped. Monitoring the exporter health is critical in production.
Is this production-ready out of the box?
The patterns are production-inspired, but the docker-compose setup is for demonstration. Production requires persistent storage, authentication, TLS, resource limits, and monitoring of the observability stack itself.

Work with a software development agency

Need help beyond evaluating fastapi-observability? DEV.co is a software development agency offering software development services and web development for teams of every size. Our software developers and web developers build custom software, web applications, APIs, and open-source observability integrations — and maintain them long-term.

Ready to Instrument Your FastAPI Services?

We help DevOps and engineering teams design and deploy scalable observability stacks. Let's discuss your tracing, metrics, and logging strategy.