This project demonstrates how to instrument a Python FastAPI application using OpenTelemetry, and export logs, metrics, and traces to a local Grafana LGTM stack via OTLP.
- ⚙️ FastAPI app with OpenTelemetry instrumentation
- 📦 Grafana OTEL-LGTM Docker image for observability pipeline:
- Loki for logs
- Grafana for dashboards
- Tempo for traces
- Mimir for metrics
- 🚀 Deployment via
docker-compose - 🛠️ Includes
run.shautomation script
git clone git@github.com:fabriciodf/otel_lgtm_py.git
cd otel_lgtm_pychmod +x run.sh
./run.shThis will:
- Remove existing containers/images
- Build your FastAPI image
- Start the FastAPI app and LGTM stack via Docker
- 🧪 FastAPI: http://localhost:8000
- 📊 Grafana: http://localhost:3000
- Login: admin / admin
The FastAPI container is instrumented with:
OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-lgtm:4317
OTEL_SERVICE_NAME=fastapi-otel
OTEL_TRACES_EXPORTER=otlp
OTEL_METRICS_EXPORTER=otlp
OTEL_LOGS_EXPORTER=otlpOpenTelemetry sends: Logs → Loki Traces → Tempo Metrics → Mimir
All visualized via Grafana dashboards
.
├── Dockerfile
├── docker-compose.yml
├── main.py
├── run.sh
└── requirements.txt
FastAPI OpenTelemetry Python SDK Grafana LGTM Docker image Docker Compose
MIT License © fabriciodf