📊 OpenTelemetry & Observability Guide¶
This guide explains how to monitor, trace, and scrape metrics across the py-phone-caller microservices stack. For turnkey Grafana dashboard provisioning and APISIX/Keycloak gateway telemetry, also see deploy/docs/07-enterprise-gateway-and-observability.md and deploy/dashboards/.
📑 Table of Contents¶
- Observability Architecture Overview
- Standardized Health, Liveness & Readiness Probes
- Prometheus Metrics Scraping (
/metrics) - Distributed Tracing with OpenTelemetry (OTel)
- Starting a Local Jaeger or Grafana Tempo Collector
- Automatic Code Instrumentation
1. Observability Architecture Overview¶
py-phone-caller provides a dual-mode observability architecture:
- Pull-based Metrics & Health/Readiness Probes: Every HTTP microservice exposes standardized
/health,/healthz,/live, dependency-aware/ready, and Prometheus/metricsendpoints. - Push-based Distributed Tracing: When enabled, services push OpenTelemetry (OTel) spans over OTLP gRPC to a centralized trace collector (Jaeger or Grafana Tempo).
[ Prometheus / Scrapers ] <--- HTTP GET /metrics, /health & /ready --- [ All py-phone-caller Microservices ]
|
[ Grafana Tempo / Jaeger ] <--- OTLP gRPC (Port 4317) -------------------------+
2. Standardized Health, Liveness & Readiness Probes¶
Every HTTP microservice automatically registers uniform JSON liveness endpoints via py_phone_caller_utils.telemetry, alongside dependency-aware readiness probes (ReadinessRegistry):
- Liveness:
GET /health,GET /healthz,GET /live(HTTP200 OKwhen the process is alive). - Readiness:
GET /ready(HTTP200 OKwhen downstream dependencies such as PostgreSQL pools, Redis broker, or Asterisk ARI/PJSIP trunk are ready; HTTP503 Service Unavailablewhen degraded).
Liveness Response Payload Schema:¶
These endpoints are used by Docker HEALTHCHECK directives, Kubernetes livenessProbe/readinessProbe manifests (deploy/k8s/ & deploy/helm/), verify_deployment.py, and the 12-Gate End-to-End Validation Checklist.
3. Prometheus Metrics Scraping (/metrics)¶
Each HTTP microservice exposes Prometheus metrics on its primary port:
| Microservice | Port | Metric URL | Liveness / Readiness URLs |
|---|---|---|---|
py_phone_caller_ui |
5000 |
http://<host>:5000/metrics |
/health, /live |
asterisk_caller |
8081 |
http://<host>:8081/metrics |
/health, /ready (Asterisk ARI & PJSIP) |
generate_audio |
8082 |
http://<host>:8082/metrics |
/health, /languages |
caller_register |
8083 |
http://<host>:8083/metrics |
/health, /ready (PostgreSQL pool) |
caller_prometheus_webhook |
8084 |
http://<host>:8084/metrics |
/health, /live |
caller_sms |
8085 |
http://<host>:8085/metrics |
/health, /ready (PostgreSQL pool) |
caller_scheduler |
8086 |
http://<host>:8086/metrics |
/health, /ready (Redis broker) |
caller_address_book |
8087 |
http://<host>:8087/metrics |
/health, /ready (PostgreSQL pool) |
Prometheus Scrape Configuration (prometheus.yml):¶
scrape_configs:
- job_name: 'py-phone-caller'
scrape_interval: 15s
static_configs:
- targets:
- '127.0.0.1:5000'
- '127.0.0.1:8081'
- '127.0.0.1:8082'
- '127.0.0.1:8083'
- '127.0.0.1:8084'
- '127.0.0.1:8085'
- '127.0.0.1:8086'
- '127.0.0.1:8087'
4. Distributed Tracing with OpenTelemetry (OTel)¶
When enabled, requests crossing service boundaries (e.g. from UI ➔ Scheduler ➔ Caller ➔ PBX) propagate W3C trace context headers, generating a unified distributed trace.
Configuration¶
Via Environment Variables (Recommended):¶
export ENABLE_TELEMETRY=true
export OTEL_EXPORTER_OTLP_ENDPOINT=http://jaeger:4317
export OTEL_SERVICE_NAME=py-phone-caller
Via settings.toml:¶
5. Starting a Local Jaeger or Grafana Tempo Collector¶
Option A: Jaeger All-In-One (Lightweight)¶
Run Jaeger in Docker or Podman:
docker run -d --name jaeger \
-p 16686:16686 \
-p 4317:4317 \
-e COLLECTOR_OTLP_ENABLED=true \
jaegertracing/all-in-one:latest
- Web UI: Open
http://localhost:16686to inspect traces.
Option B: Grafana + Tempo Stack¶
For detailed TraceQL query capabilities, see the Grafana Tempo Traces Guide.
6. Automatic Code Instrumentation¶
The shared telemetry module (py_phone_caller_utils.telemetry) automatically instruments:
aiohttp(Asynchronous HTTP server & client sessions)Flask(Web UI endpoints and request lifecycle)AsyncPG&Piccolo(PostgreSQL database queries and execution time)Celery(Task enqueueing, latency, and background worker execution)Requests(Synchronous external HTTP calls)- Process Metrics (CPU utilization, virtual memory RSS, Python GC collections)
No manual span code is required in business logic; all incoming and outgoing calls are traced out of the box.