DEV Community

Cover image for FastAPI + OpenTelemetry: Stop Debugging with grep (Use Distributed Tracing)
Manas Sharma
Manas Sharma

Posted on • Originally published at openobserve.ai

FastAPI + OpenTelemetry: Stop Debugging with grep (Use Distributed Tracing)

How do you debug a FastAPI app that talks to 5 other services?

Most people grep through logs:

  • Service A logs: "Request received ✓"
  • Service B logs: "Processing ✓"
  • Service C logs: "Query executed ✓"
  • User: "It failed"

Classic distributed systems problem: every service thinks it worked, but the request still broke somewhere.

The issue? Logs are isolated. Each service writes independently with no context about where the request came from or where it's going next.

The fix? OpenTelemetry distributed tracing. Every request gets a unique trace ID that follows it across all services—like a tracking number for API calls. When something breaks, you follow the trace ID and see exactly where it failed.

Setup takes 20 minutes. Debugging goes from hours of log archaeology to "oh, there it is" in under a minute.


Introduction to OpenTelemetry & OpenObserve

OpenTelemetry represents "an open-source observability framework" that enables developers to gather logs, metrics, and traces in a standardized manner. OpenObserve serves as a complementary platform, providing intuitive interfaces for analyzing telemetry data effectively.

Why OpenTelemetry for FastAPI?

The framework streamlines logging by integrating with existing logging libraries. This unified methodology enables consistent metadata capture across logs, traces, and metrics—making it simpler to correlate information throughout your application stack.

The Problem with Traditional Logging

When debugging microservices:

  • Each service logs separately
  • No connection between related requests across services
  • You're grep-ing through multiple log files trying to piece together what happened
  • Time zones, log formats, and missing context make correlation nearly impossible

What OpenTelemetry Solves

Distributed Tracing:

  • Every request gets a unique trace ID
  • Trace ID follows the request across all services
  • See the complete request path in one view
  • Identify exactly where failures occur

Unified Observability:

  • Logs, metrics, and traces in one place
  • Correlate log lines to specific traces
  • See performance metrics alongside request flows

OpenObserve Key Features

  • Lightweight & Deployable: Operates as a single binary on laptops or containerized environments
  • Intuitive Interface: More user-friendly than comparable tools
  • Query Flexibility: Supports both SQL and PromQL syntax
  • Integrated Alerting: Built-in capabilities eliminate additional configuration
  • Cost Efficiency: Achieves substantially lower storage expenses than competitors (140x less than Elasticsearch)

How It Works: Quick Overview

The setup involves five main components:

  1. OpenTelemetry Collector - Receives and processes telemetry data
  2. FastAPI Instrumentation - Automatically captures traces from your FastAPI app
  3. OpenObserve - Stores and visualizes logs, metrics, and traces
  4. Trace IDs - Unique identifiers that follow requests across services
  5. Dashboards - See correlated logs and traces in one view

Example: Debugging with Trace IDs

Before OpenTelemetry:

grep "user_id=12345" service1.log  # Found request
grep "timestamp=14:23:45" service2.log  # Which timezone?
grep "error" service3.log  # Too many results
# 2 hours later... still searching
Enter fullscreen mode Exit fullscreen mode

After OpenTelemetry:

# Search by trace ID across all services
grep "trace_id=abc123" *.log
# Instantly see: Request → Auth → Database → External API timeout
# 2 minutes to identify root cause
Enter fullscreen mode Exit fullscreen mode

What You'll Get

With FastAPI + OpenTelemetry + OpenObserve:

Automatic tracing for all FastAPI endpoints
Trace IDs that follow requests across microservices
Log correlation - click a trace to see all related logs
Performance metrics - response times, error rates per endpoint
Fast debugging - find issues in minutes, not hours


Ready to Set This Up?

The complete setup guide (with step-by-step instructions, code examples, and configuration files) is available on OpenObserve's blog.

What you'll learn:

  • Installing OpenTelemetry Collector
  • Configuring YAML for log and trace collection
  • Setting up OpenObserve locally or in the cloud
  • Instrumenting your FastAPI application with automatic tracing
  • Testing and analyzing traces in the OpenObserve dashboard
  • Common troubleshooting tips

👉 Read the full setup guide here


Looking for an OpenTelemetry-native backend?

If you need something that works with your existing OTel setup—self-hosted or managed cloud, SQL + PromQL querying, unified logs/metrics/traces, with enterprise features (SSO, RBAC, multi-tenancy) but without the Datadog/Elastic price tag:

Check out OpenObserve. Open-source, 140x lower storage costs, built for teams that want control over their observability stack.

Try the cloud version (14-day trial)
Download

Top comments (0)