Trace every LLM call with the full prompt and output, model name/version, token counts and cost, latency, and a correlation ID — or you can't reproduce production bugs.
Imagine a chef who cooks a slightly different dish every time, even from the same order. A customer complains a meal was awful. If all you wrote down was 'served a meal,' you're stuck — you can't recreate it. So you keep a full ticket: the exact recipe used, which chef, how long it took, how much it cost, and an order number. Now you can pull the ticket and see exactly what went wrong. An LLM trace is that ticket: the prompt sent, the answer, the model, the tokens, the time, and an ID to find it all.
Detailed answer & concept explanation~6 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Spend 5-6 minutes: anchor on the 'can I re-run this exact call?' test, then justify each field group and explain why dropping the prompt is fatal.
| Field group | Why it's logged | Cost of omitting |
|---|---|---|
| Full prompt + output | Exact input/output for replay | Can't reproduce a bad answer |
| Model name + version | Pin behavior across provider updates | Silent drift is unattributable |
| Token counts + cost | Budgets, caps, routing | No cost visibility or control |
| Latency (TTFT + total) | Perf and streaming UX | Regressions go unnoticed |
| Trace / correlation ID | Thread across services and reports | Logs can't be joined |
Real products, models, and research that use this idea.
- LangSmith capturing full prompt/response, model, token usage, cost, and latency per call with a trace ID for replay.
- Langfuse tracing nested LLM and tool spans across an agent run, correlating them under one session ID.
- OpenLLMetry / OpenTelemetry GenAI semantic conventions standardizing model, token, and latency attributes on spans.
- Provider dashboards (OpenAI, Anthropic usage logs) exposing token counts and per-request cost for budget tracking.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow do you trace prompts that contain user PII without violating retention or privacy rules?
QAt very high QPS, full traces get expensive — how do you decide what to sample?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Logging only the final user-visible answer to save storage. Without the exact prompt and model version, you can't reproduce or explain a bad response.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.