🔍 Grafana Tempo & Distributed Traces Guide¶
This guide explains how to collect, query, and visualize distributed OpenTelemetry traces across the py-phone-caller microservices stack using Grafana Tempo.
📑 Table of Contents¶
- Starting a Local Grafana + Tempo Stack
- Configuring py-phone-caller for OTLP gRPC Export
- Accessing Grafana & Tempo Datasource
- TraceQL Query Reference
- Microservices Service Name Matrix
- Visualizing the Complete Call Lifecycle Trace
1. Starting a Local Grafana + Tempo Stack¶
You can run a local Tempo and Grafana instance using Docker or Podman:
# tempo-compose.yml
services:
tempo:
image: grafana/tempo:latest
command: ["-config.file=/etc/tempo.yaml"]
volumes:
- ./tempo.yaml:/etc/tempo.yaml
ports:
- "3200:3200" # Tempo HTTP
- "4317:4317" # OTLP gRPC
- "4318:4318" # OTLP HTTP
grafana:
image: grafana/grafana:latest
ports:
- "3000:3000"
environment:
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_DISABLE_LOGIN_FORM=true
With minimal tempo.yaml:
server:
http_listen_port: 3200
distributor:
receivers:
otlp:
protocols:
grpc:
endpoint: "0.0.0.0:4317"
http:
endpoint: "0.0.0.0:4318"
storage:
trace:
backend: local
local:
path: /tmp/tempo/traces
wal:
path: /tmp/tempo/wal
Start the stack:
2. Configuring py-phone-caller for OTLP gRPC Export¶
Enable telemetry on your py-phone-caller services:
3. Accessing Grafana & Tempo Datasource¶
- Open your browser to
http://localhost:3000. - Go to Connections ➔ Data sources ➔ Add data source ➔ Tempo.
- Set URL to
http://tempo:3200(orhttp://localhost:3200if running outside container network). - Click Save & test.
- Click Explore in the left sidebar and select Tempo as the datasource.
4. TraceQL Query Reference¶
Tempo uses TraceQL for fast span and trace search:
Find all traces from a specific microservice:¶
Find traces containing errors:¶
Find slow call execution spans (> 2 seconds):¶
Trace search for specific HTTP routes:¶
{span.http.route = "/call_to_queue" || span.http.route = "/make_audio" || span.http.route = "/send_sms"}
Complex multi-service trace query:¶
Find traces originating from the UI that caused an error in the Scheduler or Caller:
5. Microservices Service Name Matrix¶
When querying in Grafana, filter by these registered service names:
| Service Name | Component Role |
|---|---|
py_phone_caller_ui |
Multilingual Web Management Console & BFF |
asterisk_caller |
Outbound Call Queue, ARI Controller & Circuit Breaker |
generate_audio |
Multi-Engine Offline TTS Synthesis (Kokoro, Silero, Piper, MMS) |
caller_register |
Database Migrations & Call State Registry |
caller_prometheus_webhook |
Alertmanager & OpenAlert Webhook Receiver |
caller_sms |
Dual-Channel SMS & SIP MESSAGE Dispatcher |
caller_scheduler |
Delayed Call Scheduler |
caller_address_book |
Dual-Channel Contact Directory & On-Call Rotation |
asterisk_ws_monitor |
Asterisk Stasis WebSocket Listener |
asterisk_recaller |
Call Retry & Backup Escalation Loop |
celery_worker |
Celery Priority Task Consumer (p0_emergency, default) |
6. Visualizing the Complete Call Lifecycle Trace¶
In Grafana's waterfall view, an end-to-end incident call displays as a connected hierarchy:
[ py_phone_caller_ui: POST /schedule_call ] (2.1s)
├── [ caller_scheduler: POST /schedule_call ] (15ms)
│ └── [ Redis: Celery Task Enqueue ] (2ms)
├── [ celery_worker: do_this_call ] (1.8s)
│ └── [ asterisk_caller: POST /call_to_queue ] (12ms)
│ └── [ caller_address_book: GET /contact_on_call ] (4ms)
│ └── [ PostgreSQL: SELECT FROM address_book ] (1ms)
└── [ asterisk_ws_monitor: StasisStart Event ] (850ms)
├── [ caller_register: POST /msg ] (5ms)
├── [ generate_audio: POST /make_audio ] (620ms)
│ └── [ Neural Model: Kokoro / Silero / Piper TTS Synthesis ] (580ms)
└── [ asterisk_caller: POST /play ] (10ms)
Clicking any individual span reveals:
- Exact HTTP status codes and headers
- Database query strings and execution duration
- Python exception stack traces in case of failure
For Prometheus scraping, health/readiness probes, and turnkey Grafana dashboards, see the OpenTelemetry & Observability Guide and deploy/docs/07-enterprise-gateway-and-observability.md.