This project sets up a complete observability pipeline using Docker Compose, including:
-
OpenTelemetry Collector – Receives and processes telemetry data (both metrics and traces)
-
Prometheus – Scrapes and stores metrics data
-
Grafana – Visualizes the metrics with dashboards
-
FastAPI Application – An instrumented web application that sends trace data to the Collector
For additional examples and extended OpenTelemetry solutions, check out the Open-Telemetry-Solutions repository.
📁 Project Structure
The repository is organized as follows:
-
docker-compose.yml: Defines all four services (Collector, Prometheus, Grafana, FastAPI).
-
otel-collector-config.yaml: Configures the Collector to receive OTLP telemetry and export metrics and traces.
-
prometheus.yml: Configures Prometheus to scrape metrics from the Collector.
-
datasource.yml: Provisions Grafana with a Prometheus datasource.
-
fastapi-app/: Contains the FastAPI application that sends trace data to the Collector.
🚀 Getting Started
1. Clone the Repository
2. Run Docker Compose
Start all services with:
This command will launch:
-
OpenTelemetry Collector on ports 4317 (gRPC) and 4318 (HTTP)
-
Prometheus on port 9090
-
Grafana on port 3000
-
FastAPI Application on port 8000
🛠️ Configuration Files
docker-compose.yml
The Compose file integrates all the services together. Notice that the FastAPI service is built from the local directory and configured to send trace data to the Collector endpoint:
otel-collector-config.yaml
This file configures the Collector to receive OTLP data for both metrics and traces and to send metrics to Prometheus. Traces are sent to a debug exporter which logs them for easy verification.
prometheus.yml
This file instructs Prometheus to scrape metrics from the Collector’s Prometheus exporter:
grafana/provisioning/datasources/datasource.yml
Grafana is automatically provisioned with Prometheus as its default datasource:
🚀 FastAPI Application
The FastAPI service is instrumented with OpenTelemetry to send trace data to the Collector.
fastapi-app/Dockerfile
fastapi-app/requirements.txt
fastapi-app/main.py
🖥️ Access the Interfaces
-
Grafana: http://localhost:3000
Login:admin / admin
-
Prometheus: http://localhost:9090
-
FastAPI Application: http://localhost:8000
The/
endpoint returns a welcome message, and/trigger
generates a manual trace.
📡 Sending Telemetry
Your instrumented FastAPI app automatically sends trace data to the Collector at:
-
http://otel-collector:4318/v1/traces
(within Docker networks)
From outside Docker, you can test using:
-
http://localhost:4318/v1/traces
(if you map the port externally)
For metrics, send to:
-
http://localhost:4318/v1/metrics
(HTTP) or -
grpc://localhost:4317
(gRPC)
You can use your own instrumented applications or tools like otel-cli.
⚠️ Port 55679 Error Fix (zPages)
If you encounter this error:
Solutions:
-
Option 1: Remove the line mapping port
55679
fromdocker-compose.yml
if you're not using zPages. -
Option 2: Change it to a free port, for example:
Then restart with:
🧱 Build Dashboards in Grafana
Once your metrics are coming in:
-
Log into Grafana at http://localhost:3000.
-
Create new dashboards to visualize key metrics such as:
-
Request rates
-
Custom app metrics
-
Error counts
-
And more!
-
📚 Additional Resources
Explore more solutions for OpenTelemetry and observability by checking out the Open-Telemetry-Solutions repository. It contains extended examples, integrations, and best practices you might find useful for your projects.
📬 Feedback & Contributions
Have ideas or improvements? Open an issue or submit a pull request! Contributions are welcome.
📄 License
This project is licensed under the MIT License.