Observability & Monitoring
After this lesson, you will be able to:
- Design a monitoring system that catches data changes, model quality drops, and performance issues before your users notice
- Set up tracing for LLM applications so you can see exactly what happened inside a complex AI request
- Build alerts and dashboards that tell you what actually matters, without drowning you in noise
Before you start
#The Silent Failure Problem
If you have ever shipped a feature and assumed "no errors = everything is fine," this lesson will change how you think about production systems forever. ML models can silently serve terrible results for weeks without a single error log. Let's learn how to catch that.
#The Three Pillars of ML Observability
Figure
The three pillars of observability answer different questions. Metrics are aggregated numbers over time (latency p99, throughput, GPU utilisation) and tell you WHAT is happening. Logs are individual timestamped events and tell you WHAT HAPPENED in one specific case. Traces follow a single request across every service and component it touched, and tell you WHERE the time went. You need all three: metrics reveal that something broke, logs reveal what, traces reveal where.
Traditional observability has three pillars: logs, metrics, and traces. ML observability extends each:
#1. Metrics (What is happening?)
- Latency (P50, P95, P99)
- Throughput (requests per second)
- Error rate (4xx, 5xx)
- GPU utilization, memory usage
- Queue depth
Model-specific metrics
- Prediction distribution (are outputs changing?)
- Confidence distribution (is the model becoming less certain?)
- Feature distribution (are inputs changing?)
- Feedback metrics (thumbs up/down rate, click-through, conversion)
- Token usage and cost per request (for LLMs)
#2. Logs (What happened for this request?)
Standard logs
- Request/response payloads (sampled, with PII redaction)
- Processing time breakdown (preprocessing, inference, postprocessing)
- Model version, feature values used
ML-specific logs
- Prediction confidence and alternatives
- Feature importance for this specific prediction
- Retrieval results (for RAG systems)
- Agent tool calls and reasoning steps (for agents)
#3. Traces (How did the system process this request?)
For complex ML systems (RAG, agents, multi-model pipelines), a single user request triggers multiple sub-operations:
LLM Request Trace
#Drift Detection: When the World Changes
#Data Drift
The input data distribution changes over time. The model was trained on one distribution but now sees a different one.
Causes
- Seasonal changes (holiday shopping, weather patterns)
- User demographic shifts (marketing campaign brings new user types)
- Upstream data pipeline changes (a feature column changes meaning)
- External events (pandemic, economic crisis, competitor actions)
Detection methods
| Method | How It Works | Best For |
|---|---|---|
| PSI (Population Stability Index) | Compare binned distributions of training vs production data | Numerical features |
| KS Test (Kolmogorov-Smirnov) | Maximum distance between two CDFs | Numerical features |
| Chi-squared Test | Compare categorical frequency distributions | Categorical features |
| Jensen-Shannon Divergence | Symmetric KL divergence between distributions | Any distribution |
| Embedding drift | Distance between embedding centroids over time | Text, image inputs |
Try it! Simulate drift yourself: generate two sets of random numbers, one fromrandom.gauss(0, 1)and another fromrandom.gauss(0.5, 1)(a small mean shift). Compute the mean of each set and compare them. That 0.5 shift is data drift in action, small enough to miss by eye, large enough to degrade a model.
Tests: Verify PSI is near 0 for identical distributions, moderate for slight shifts, and large for significant shifts.
#Concept Drift
The relationship between inputs and outputs changes, even if the input distribution stays the same.
Detection
- Monitor ground-truth feedback: if labeled outcomes become available (even delayed), compare model predictions to actuals
- Track prediction accuracy over rolling time windows
- Use adaptive models that explicitly model temporal dynamics
#Prediction Drift
The model's output distribution changes, even without data or concept drift.
Causes
- Model version change (silent deployment of wrong model)
- Feature pipeline bug (upstream change)
- Infrastructure issue (GPU returning wrong results, rare but real)
Your production model's prediction confidence has been steadily declining over 2 weeks, even though prediction accuracy has not changed yet. What is happening and what should you do?
Declining confidence is often the leading indicator of drift. The model is encountering inputs that are further from its training distribution, so it becomes less certain. Accuracy may still look fine if the model is "correctly uncertain," but eventually it will start making wrong predictions. This is your early warning system, investigate drift now, before accuracy drops.
The dashboard above watched drift and latency. This second one watches six signals at once: latency p50 and p99, throughput, accuracy, and shift scores for predictions and features. It lets you inject four kinds of incident.
Do: Inject drift. Press Reset and inject the latency spike alone. Press Reset again and inject the schema change.Notice: Drift ramps in over 18 steps: accuracy slides from 94.2% toward 85%, and both shift scores climb past the 0.20 alert line. The latency spike lights up p99 and the 250 ms alert but leaves accuracy alone. The schema change moves the feature shift score most.Why: Different faults light different signals, so no single metric covers every failure. Scripted stand-in, not a real model: the incidents are preset ramps, the shift scores are given numbers and are not computed from the plotted bars. Accuracy updates live here only because the lab knows the truth. A real system waits for labels.
#LLM-Specific Observability
LLMs introduce unique observability challenges:
What to track per request
- Input/output token counts and cost
- Time to first token (TTFT) and tokens per second (TPS)
- Model version and parameters (temperature, top_p)
- System prompt hash (did the system prompt change?)
- Retrieval context (for RAG: what chunks were retrieved? relevance scores?)
- Tool calls (for agents: which tools were invoked? did they succeed?)
- User feedback (explicit thumbs up/down, implicit engagement signals)
Tracing tools (2024-2026 landscape)
- Langfuse. Open-source, self-hostable. Traces, scores, datasets, prompt management, online evals. Default for most teams running their own stack.
- LangSmith. LangChain's tracing/eval platform. Tight integration with LangChain/LangGraph; supports any SDK via OpenTelemetry exporter.
- Arize Phoenix. Open-source. Strong on embedding drift and structured trace search; pairs with Arize's commercial product for production monitoring.
- Helicone. Proxy-based (drop-in OpenAI proxy). Cost analytics, caching, retries, minimal code changes.
- OpenLLMetry (Traceloop), Vendor-neutral OpenTelemetry semantic conventions for LLMs. Emit OTel spans, ship to any backend (Datadog, Honeycomb, Grafana Tempo).
- Cloudflare AI Gateway. Edge-deployed observability + caching + rate limiting for any LLM provider.
- Braintrust / Patronus / Galileo. Evaluation-first platforms that also do tracing.
#Sampling Budget Math
You cannot afford to log every byte of every trace at 10K RPS. Work the sampling budget explicitly:
#Key Takeaways
- ML systems fail silently. Unlike traditional software that crashes with errors, a degrading model continues serving predictions with increasing confidence in wrong answers, making monitoring essential
- Monitor for data drift, concept drift, and model degradation. Data drift means input distributions changed, concept drift means the relationship between inputs and outputs changed, and both cause model quality to silently erode
- LLM tracing tools debug complex chains. Langfuse, Arize, and similar tools trace token flow through multi-step agent pipelines, making it possible to identify which step in a chain caused a bad output
- Good alerting distinguishes signal from noise. Alert on actionable metrics (prediction quality, feature distribution shifts, latency spikes) rather than noisy signals, and build runbooks for each alert type
#Quick Check
What distinguishes data drift from concept drift?