Why this matters
You can't fix what you can't see. Observability answers "is it working, and if not, where?" in minutes instead of hours. AI systems need it more than most: quality can degrade without a single error, and cost can spike without a traffic change.
The three signals
| Signal | Answers | Example |
|---|---|---|
| Logs | What happened in this specific event? | {"event":"llm.retry","provider":"x","attempt":2,"request_id":"..."} |
| Metrics | How is the system behaving overall? | p95 latency, error rate, queue depth, cost per hour |
| Traces | Where did time go in this request, across services? | Span tree: API → retrieval → model → validation |
- RED for services: Rate, Errors, Duration.
- USE for resources: Utilisation, Saturation, Errors.
- OpenTelemetry is the vendor-neutral standard for emitting all three.
How to do it
logger.info("evaluation.completed", extra={
"request_id": request_id, "tenant_id": tenant_id,
"model": model, "prompt_version": PROMPT_VERSION,
"tokens_in": usage.input_tokens, "tokens_out": usage.output_tokens,
"latency_ms": elapsed_ms, "outcome": "pass",
}) # never the prompt text, document content, email or API key
- Structured (JSON) logs with consistent field names, searchable by
request_id. - Propagate a request ID from the edge through every service and job.
- Log field names, not values, for sensitive operations: an audit trail can record "updated fields: diagnosis, address" without the diagnosis (P12).
Alerting
Alert on symptoms users feel (error rate above X% for 5 minutes, p95 above the SLO, queue age growing, cost per hour above budget). Every alert must be actionable and link to a runbook. Define SLOs (for example "99.5% of requests succeed in under 2 s over 30 days") and alert on burning the error budget too fast.
What changes for AI
Add per-call fields: model and version, prompt version, tokens in/out, cache hits, cost, latency split into time-to-first-token and total, outcome (success, schema violation, refusal, fallback). Then dashboards for cost per successful task and quality signals. Part 10 covers this in depth (Q36).
Common mistakes
- Unstructured
printstatements. - Logging full prompts and documents containing personal data.
- Alert fatigue from noisy, non-actionable alerts.
- Only averages on dashboards.
Interview follow-ups
- "Logs, metrics or traces: which first?" Metrics to know something's wrong, traces to find where, logs to see exactly what happened. Start with RED metrics and request IDs in logs.
- "What's an SLO and an error budget?" A target (99.5% under 2 s over 30 days); the budget is the allowed failure (0.5%). Burning it fast pauses risky releases.
- "High-cardinality labels?" Don't put user IDs or request IDs in metric labels (it explodes storage); put them in logs and traces.
Check yourself
What are RED metrics?
Rate (requests per second), Errors (failed requests), Duration (latency distribution, as percentiles). The minimum dashboard for any service.
Why propagate a request ID?
So you can find every log line and span for one user's request across the API, workers and external calls, which turns a vague bug report into a precise timeline.
Build it
Add JSON logging with request IDs to your service, a /metrics endpoint (Prometheus format) with RED metrics, and OpenTelemetry tracing for one outbound call; view a trace locally (Jaeger in Docker).