19. Monitoring AI#
AI systems can degrade quietly as data, users, and providers change. This chapter shows how to observe AI services with logs, traces, and metrics, detect drift in inputs and output quality, and keep usage costs under control.
Observability: Logs, traces, and metrics show what an AI service is doing and why.
Drift Detection: Changes in inputs or output quality signal that a system needs attention.
Usage and Budgets: Usage tracking, budget alerts, and optimization levers keep AI spending predictable.
Chapter Video
This explainer shows why AI services need observability beyond ordinary uptime monitoring, and what traces and quality signals reveal about a model in production.
LLM Observability Explained: Why Your AI Lies to You (9:38) by Devsplainers
Hosted on YouTube; property of its original creator, embedded here for educational reference only.
Learning Objectives
By the end of this chapter, you will be able to:
Instrument an AI service with structured logs, traces, and metrics.
Define service-level objectives for latency, errors, and quality.
Detect data drift and quality drift from logged results.
Track usage and cost and set budget alerts.
Analyze AI service logs for drift and cost in Python.
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Observability |
The ability to understand a system’s internal state from its outputs. |
2 |
Structured log |
A log record with named fields that software can search and aggregate. |
3 |
Trace |
A record of one request’s path through the components of a system. |
4 |
Metric |
A numeric measurement collected over time, such as latency or error rate. |
5 |
Service-level objective (SLO) |
A target for a service’s reliability or performance. |
6 |
LLMOps |
Practices for deploying, monitoring, and maintaining language model applications. |
7 |
Data drift |
A change in the distribution of a system’s inputs over time. |
8 |
Quality drift |
A decline in output quality over time. |
9 |
Alert |
An automatic notification when a metric crosses a threshold. |
10 |
Dashboard |
A visual display of key metrics. |
11 |
Usage tracking |
Recording tokens, requests, and cost by user, feature, or team. |
12 |
Budget alert |
A notification when spending approaches a set limit. |
13 |
Span |
An operation within a request trace. |
14 |
Percentile convention |
The rule for selecting a distribution cutoff. |
15 |
Reference window |
A known comparison period for monitoring. |
16 |
Delayed label |
Correctness evidence arriving after a prediction. |
17 |
Total variation distance |
Half the summed absolute share differences between distributions. |
18 |
Run-rate projection |
Extrapolation under a constant-activity assumption. |
19 |
Usage allocation |
Assigning consumption to features or teams. |
20 |
Unresolved usage |
Consumption not yet established for an attempt. |