Observability Architecture Guide
Overview
Observability in LiteLLM-RS is built from three runtime pieces:
- HTTP metrics —
MetricsMiddleware (src/server/middleware/metrics.rs) counts requests with process-local atomics and renders Prometheus text format on demand. No prometheus crate is used; series are hand-rendered and use the gateway_ prefix except the standalone rate_limiter_degraded_total counter.
- Health/status routes —
src/server/routes/health.rs mounts /health, /health/ready, /health/detailed, /status, /version, and /metrics on the main HTTP server.
- Callback exporters — configured under
monitoring.callbacks, the OpenTelemetryIntegration (OTLP/HTTP JSON), DataDogIntegration, and LangfuseIntegration receive real LLM lifecycle events through the CallbackDispatcher stored in AppState (exposed as RuntimeObservability).
┌─────────────────────────────────────────────────────────────────┐
│ LiteLLM Gateway │
├─────────────────────────────────────────────────────────────────┤
│ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │
│ │ Metrics │ │ Health/status │ │ Callback │ │
│ │ middleware │ │ routes │ │ dispatcher │ │
│ └───────┬───────┘ └───────┬───────┘ └───────┬───────┘ │
└──────────┼──────────────────┼──────────────────┼───────────────┘
▼ ▼ ▼
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
│ Prometheus │ │ LB / K8s probes │ │ OTLP / Datadog / │
│ scrapes /metrics │ │ + JSON status │ │ Langfuse backends│
└──────────────────┘ └──────────────────┘ └──────────────────┘
Configuration
The section is monitoring: at the top level of config/gateway.yaml (deserialized as
GatewayConfig.monitoring, src/config/models/gateway.rs). The outer monitoring models
use #[serde(deny_unknown_fields)], but callback backend payloads such as
OpenTelemetryConfig do not all make that guarantee; strictness follows the concrete
deserialized struct.
monitoring:
metrics:
enabled: true # gates MetricsMiddleware (src/server/http.rs)
port: 9090 # default 9090; validated > 0 when enabled
path: "/metrics" # validated non-empty, starts with '/'
interval_seconds: 15
tracing:
enabled: false
endpoint: null # REQUIRED when enabled: true (config validation)
service_name: "litellm-rs"
sampling_rate: 0.1
jaeger: null # or {agent_endpoint, service_name}
health:
path: "/health"
detailed: true
logging: null # or {level, format: text|json|structured, outputs}
callbacks:
queue_capacity: 1024
timeout_ms: 5000
backends: [] # {type: opentelemetry|datadog|langfuse, config: {...}}
Wiring notes (verified against current code):
metrics.enabled is the only metrics key with runtime effect: it wraps the app in
Condition::new(metrics_enabled, MetricsMiddleware) (src/server/http.rs). The
/metrics route itself is hardcoded in routes::health::configure_routes; port,
path, and interval_seconds are parsed and validated but not consumed by runtime
wiring today.
tracing.enabled only appears in the startup summary log (src/lib.rs); OTLP trace
export is configured through callbacks.backends, not the tracing: section.
logging is parsed/validated but the log subscriber is initialized in src/main.rs
init_logging from the CLI/env level, not from this section.
health.path and health.detailed are parsed and validated, but route registration is
hardcoded to /health, /health/ready, and /health/detailed; neither field changes
the runtime health surface today.
References
- reference/metrics.md — the full
gateway_* metric inventory, how the middleware records, and the /metrics renderer.
- reference/tracing-and-logging.md — log subscriber init, request IDs, access-log events, and the OTLP/Datadog/Langfuse callback exporters.
- reference/health-checks.md — health/readiness/detailed endpoints, response models, and the aggregate readiness rule.
- reference/alerting.md — Prometheus alert rules built on real
gateway_* series.
- reference/best-practices.md — metric type selection, log context, label cardinality, and graceful telemetry degradation.
1---2name: observability-architecture3description: LiteLLM-RS Observability Architecture. Covers the Prometheus-format metrics rendered by the metrics middleware and /metrics endpoint, health/readiness endpoints, request logging, and the OpenTelemetry/Datadog/Langfuse callback exporters. Use when adding or changing metrics or log instrumentation, implementing or debugging health checks, wiring Prometheus alert rules, or configuring the monitoring stack.4---56# Observability Architecture Guide78## Overview910Observability in LiteLLM-RS is built from three runtime pieces:11121. **HTTP metrics** — `MetricsMiddleware` (`src/server/middleware/metrics.rs`) counts requests with process-local atomics and renders Prometheus text format on demand. No `prometheus` crate is used; series are hand-rendered and use the `gateway_` prefix except the standalone `rate_limiter_degraded_total` counter.132. **Health/status routes** — `src/server/routes/health.rs` mounts `/health`, `/health/ready`, `/health/detailed`, `/status`, `/version`, and `/metrics` on the main HTTP server.143. **Callback exporters** — configured under `monitoring.callbacks`, the `OpenTelemetryIntegration` (OTLP/HTTP JSON), `DataDogIntegration`, and `LangfuseIntegration` receive real LLM lifecycle events through the `CallbackDispatcher` stored in `AppState` (exposed as `RuntimeObservability`).1516```17┌─────────────────────────────────────────────────────────────────┐18│ LiteLLM Gateway │19├─────────────────────────────────────────────────────────────────┤20│ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │21│ │ Metrics │ │ Health/status │ │ Callback │ │22│ │ middleware │ │ routes │ │ dispatcher │ │23│ └───────┬───────┘ └───────┬───────┘ └───────┬───────┘ │24└──────────┼──────────────────┼──────────────────┼───────────────┘25 ▼ ▼ ▼26┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐27│ Prometheus │ │ LB / K8s probes │ │ OTLP / Datadog / │28│ scrapes /metrics │ │ + JSON status │ │ Langfuse backends│29└──────────────────┘ └──────────────────┘ └──────────────────┘30```3132---3334## Configuration3536The section is `monitoring:` at the top level of `config/gateway.yaml` (deserialized as37`GatewayConfig.monitoring`, `src/config/models/gateway.rs`). The outer monitoring models38use `#[serde(deny_unknown_fields)]`, but callback backend payloads such as39`OpenTelemetryConfig` do not all make that guarantee; strictness follows the concrete40deserialized struct.4142```yaml43monitoring:44 metrics:45 enabled: true # gates MetricsMiddleware (src/server/http.rs)46 port: 9090 # default 9090; validated > 0 when enabled47 path: "/metrics" # validated non-empty, starts with '/'48 interval_seconds: 1549 tracing:50 enabled: false51 endpoint: null # REQUIRED when enabled: true (config validation)52 service_name: "litellm-rs"53 sampling_rate: 0.154 jaeger: null # or {agent_endpoint, service_name}55 health:56 path: "/health"57 detailed: true58 logging: null # or {level, format: text|json|structured, outputs}59 callbacks:60 queue_capacity: 102461 timeout_ms: 500062 backends: [] # {type: opentelemetry|datadog|langfuse, config: {...}}63```6465Wiring notes (verified against current code):6667- `metrics.enabled` is the only metrics key with runtime effect: it wraps the app in68 `Condition::new(metrics_enabled, MetricsMiddleware)` (`src/server/http.rs`). The69 `/metrics` route itself is hardcoded in `routes::health::configure_routes`; `port`,70 `path`, and `interval_seconds` are parsed and validated but not consumed by runtime71 wiring today.72- `tracing.enabled` only appears in the startup summary log (`src/lib.rs`); OTLP trace73 export is configured through `callbacks.backends`, not the `tracing:` section.74- `logging` is parsed/validated but the log subscriber is initialized in `src/main.rs`75 `init_logging` from the CLI/env level, not from this section.76- `health.path` and `health.detailed` are parsed and validated, but route registration is77 hardcoded to `/health`, `/health/ready`, and `/health/detailed`; neither field changes78 the runtime health surface today.7980---8182## References8384- [reference/metrics.md](reference/metrics.md) — the full `gateway_*` metric inventory, how the middleware records, and the /metrics renderer.85- [reference/tracing-and-logging.md](reference/tracing-and-logging.md) — log subscriber init, request IDs, access-log events, and the OTLP/Datadog/Langfuse callback exporters.86- [reference/health-checks.md](reference/health-checks.md) — health/readiness/detailed endpoints, response models, and the aggregate readiness rule.87- [reference/alerting.md](reference/alerting.md) — Prometheus alert rules built on real `gateway_*` series.88- [reference/best-practices.md](reference/best-practices.md) — metric type selection, log context, label cardinality, and graceful telemetry degradation.