Deployed Lab

Module 5 · Reliability, observability and cost · Chapter 17 · Free

Observability for AI services: traces, tokens and quality signals

20 min1 clickable picture1 hands-on lab1 predict, 2 quick quizzes, 5-question final quiz5-min video review
In 30 seconds

The picture: ordinary metrics say the shop is open. AI observability says whether the advice was any good.

What this chapter gives you
The cold open

Copperline is a made up B2B SaaS company. One Tuesday, Priya Nair, its staff platform engineer, watched every graph stay green while Ana, the support lead, escalated copilot complaints.

The platform measured the machine, not the work.

The plan for this chapter
  1. Why ordinary service metrics miss AI failures.
  2. The per request record.
  3. One trace across gateway, retrieval, engine and tools.
  4. Quality signals, dashboards and alerts.
  5. Log hygiene for data carrying prompts.
  6. The picture, a worked example, and a design lab.

Next: the gap between a healthy service and a helpful one.

Step 1: Up and wrong, the failure ordinary metrics miss

Ordinary metrics suit deterministic services: fast code usually means a right answer. A model breaks that link.

Copperline failed quietly: stale retrieval, a prompt change lengthening answers, a fallback answering on timeouts, refusals rising for one topic. None raised a 5xx.

Think of a restaurant check that counts clean plates but never tastes food. Where the picture breaks down:

Chapter 4, SLOs for AI services: latency, throughput and quality, set the targets. This chapter builds the signals. For token basics, see Tokens and context windows.

Next: the single record that makes every later question answerable.

Step 2: The per request record, your unit of truth

Log one structured record per request, written at the end by the gateway. Keep it small and typed. Raw prompts do not belong in it (Step 6).

{
  "trace_id": "illustrative-id-7f3a",
  "workload": "support-copilot",
  "model": "copilot-model", "model_version": "v12",
  "prompt_template": "support-answer", "prompt_version": "p34",
  "index_version": "helpdocs-2026-11-20",
  "tokens_in": 1240, "tokens_out": 286,
  "ttft_ms": 620, "latency_ms": 3810,
  "cache": "hit", "retrieval_count": 5,
  "tools": ["doc_search"], "fallback": false,
  "finish_reason": "completed", "status": 200
}

Use the same field names on all three workloads. Count tokens from the engine response, not characters.

Next: following one request through four systems with one id.

Step 3: One trace id across gateway, retrieval, engine and tools

The record is the summary, the trace is the story. The gateway creates a trace id and passes it downstream.

  1. Gateway span: auth, routing, rate limit decision, total time.
  2. Retrieval span: query time, index version, chunks returned.
  3. Engine span: queue time, prefill, time to first token, decode, tokens in and out.
  4. Tool spans: each tool call, timed, with success or failure.

Support pastes the trace id and Tom sees the whole path. Without it, he greps four log streams and guesses.

Think of one parcel tracking number at every depot. Where it breaks down:

Sample full traces if volume is high, but keep the record for every request and traces for every error.

Next: the signals that say whether answers are any good.

Step 4: Quality signals, measured on a sample

Priya layers four cheap quality signals, each catching a different failure.

Attach scores back to the trace id. That join lets you compare prompt versions on the same index.

Predict first:

Each signal tracks a different cause. Longer answers raise tokens, latency and cost. Refusals track scope and policy behaviour, which this change did not touch. That independence is the point: watch each signal for its own failure family.

Next: the three dashboards, and the line between a page and a ticket.

Step 5: Three dashboards, and alerts that earn a page

Priya keeps three dashboards.

Page only on live, fixable harm.

Next: what must never land in those logs in the first place.

Step 6: Log hygiene, because prompts carry customer data

Prompts quote invoices and account details. Retrieved documents carry the same. Storing raw prompts makes logs a poorly guarded copy of customer data.

Priya's test: if this store leaked, what must we disclose? Keep that answer small.

Next: the picture, one request leaving a record at every stage.

Step 7: The picture, one request, four spans, one record

Press Next to follow one request.

One traced AI request A request passes the gateway, retrieval, the serving engine and a tool, sharing one trace id, and ends as one per request record feeding three dashboards. Gatewaytrace id born Retrievalchunks counted Enginetokens and TTFT Tool calltimed span Per request recordone row, all fields Three dashboardslatency cost quality
  1. The gateway assigns the trace id, records routing and starts the clock.
  2. Retrieval logs index version and chunk count under the same id.
  3. The engine span carries queue time, time to first token, tokens in and out.
  4. Each tool call is a timed child span, so a slow tool cannot hide.
  5. Summary fields land in one record keyed by the trace id.
  6. Three dashboards are views over the same records, plus sampled scores.

Next: a worked example where the obvious suspect is innocent.

Step 8: Worked example, a latency rise that was not the engine

Thursday, copilot p95 latency rose from an illustrative 2.1 seconds to 3.5 seconds. The first guess was a sick engine. The records said otherwise.

1. Split the latency. Time to first token p95 barely moved: an illustrative 0.60 to 0.65 seconds. Queue time was flat. The extra 1.4 seconds sat in decode.

2. Check tokens out. Average tokens out rose from an illustrative 180 to 335. A Wednesday prompt release had asked for fuller answers with examples.

3. Decode math. Extra output: 335 minus 180 = 155 tokens. At an illustrative 110 tokens per second, extra time is 155 / 110, about 1.4 seconds. That matches the rise.

4. Cost check. Tokens out rose by 155 / 180, about 86 percent. Cost per request rose with it, as the cost dashboard showed.

5. Decision. No engine change, no extra GPU. Priya and Ana shortened the prompt, tokens out fell back, and latency and cost followed.

With tokens split from time to first token, this was a ten minute read, not a day of engine tuning.

Next: the lab, designing telemetry for a symptom.

Step 9: Hands-on lab, design the record and the alerts

Why this exercise: observability is designed before the incident. Turn a vague symptom into fields and alert levels.

The symptom: extraction users say results feel slower after lunch and some totals look wrong, but the pipeline shows no errors.

Lab: Copperline's dashboards stay green while real problems hide underneath. This lab runs in your browser and needs JavaScript enabled.

What to notice

Next: a field note and the mix-ups.

Field note, November 2026

In production practice, the cheapest win is often a shared trace id and a disciplined per request record, not a new tool. Tooling varies, so test any vendor claim about automatic quality detection on your own sampled data.

Mix-ups to avoid

Chapter quiz

Five questions, 70% to pass.

Review this chapter in 5 minutes

Watch the whole chapter recapped: the per request record, one trace id across four systems, sampled quality signals, and page versus ticket alerts.

Decision rule: user hurt now, human can act now? Page. Drifting? Ticket. Only explains? Chart it.

Review

Glossary

Trace id
One id shared by every span of a request.
Span
One timed stage in a trace. Example: the retrieval span.
Per request record
One summary row per request: versions, tokens, timing, outcome.
Time to first token
Wait until the first output token arrives.
Finish reason
Why generation stopped: completed, limit, refusal, timeout.
Retrieval count
Chunks returned for a request. Zero is a warning sign.
Eval score
Automated grade on a sampled answer against set checks.
Fallback rate
Share answered by a backup path. A jump signals main path trouble.
Refusal rate
Share of requests the model declines, by topic and version.
Redaction
Removing sensitive values before storage.

Next: "Eval gates in CI/CD: shipping model and prompt changes safely".