Telemetry

The Telemetry addon provides OpenTelemetry distributed tracing, Prometheus metrics, and health checks.

1. Enable

[proxy]
addons = ["telemetry"]

No additional database tables required.

2. Prometheus Metrics

2.1 Endpoint

GET /metrics

Optional Bearer Token authentication:

[metrics]
bearer_token = "my-metrics-token"

2.2 RustPBX Core Metrics

MetricTypeDescription
rustpbx_calls_totalCounterTotal calls
rustpbx_call_duration_secondsHistogramCall duration distribution
rustpbx_call_talk_time_secondsHistogramActual talk time

2.3 Metrics Configuration

[metrics]
enabled = true
bearer_token = ""             # Leave empty for no authentication
export_interval_secs = 15     # Push interval (OTLP)

3. OpenTelemetry Tracing

3.1 Configuration

config/otel.toml:

[otel]
enabled = true
endpoint = "http://jaeger:4317"      # OTLP gRPC endpoint
service_name = "rustpbx"
sample_ratio = 0.1                   # 10% sampling rate
export_metrics = true                # Also export metrics
export_logs = false                  # Whether to export logs

3.2 Supported Backends

BackendEndpoint Format
Jaegerhttp://jaeger:4317
Grafana Tempohttp://tempo:4317
Datadoghttps://trace.agent.datadoghq.com/api/v0.2/traces
Any OTLP-compatible backendhttp://host:4317

3.3 Sampling Strategy

  • Head-based sampling
  • sample_ratio = 1.0: 100% sampling (development/debugging)
  • sample_ratio = 0.1: 10% sampling (recommended for production)
  • sample_ratio = 0.01: 1% sampling (high traffic)

3.4 Trace ID Injection

Trace IDs are automatically injected into log records for easy log-to-trace correlation.

4. Health Check

GET /healthz

Returns JSON:

{
  "status": "ok",
  "uptime_secs": 86400,
  "version": "0.4.4",
  "active_calls": 42
}

Use cases:

  • Kubernetes liveness/readiness probe
  • Load Balancer health check
  • Monitoring alerts

5. Grafana Integration

5.1 Prometheus Scrape

# prometheus.yml
scrape_configs:
  - job_name: 'rustpbx'
    bearer_token: 'my-metrics-token'
    static_configs:
      - targets: ['203.0.113.10:8080']

5.2 Recommended Dashboard Panels

PanelMetric
Total callsrustpbx_calls_total
Call duration distributionrustpbx_call_duration_seconds histogram
Active callsrustpbx_active_calls gauge
CPSrate(rustpbx_calls_total[1m])

5.3 Wholesale Metrics (if enabled)

PanelMetric
Revenuewholesale_revenue_microcurrency_total
Costwholesale_cost_microcurrency_total
Profitwholesale_profit_microcurrency_total
ASRCalculated from CDR

5.4 Call Center Metrics (if enabled)

PanelMetric
Queue countcc_queue_length
Available agentscc_agents_available
SLAcc_sla_percentage