By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
At 09:14 a customer reported a wrong refund amount. The team had logs: 40,000 lines for that hour, one line per model call, each with a truncated prompt and no identifier in common.
They could not say which retrieval result the model saw, which tenant paid for the call, which tool returned the wrong figure, or who approved the refund. The incident took two days to close.
The fix was not more logging. It was a trace: one identifier per request, attached to every model call, tool call and approval, with the sensitive fields redacted before the data left the request path.
Observability is not one store. Four signals answer four different questions, and a design that keeps only one of them cannot be operated.
| Signal | Question it answers | Keep | Do not keep |
|---|---|---|---|
| Trace with spans | Where did the time and the failure go? | Trace id, span ids, tool name, status, token counts, duration | Full prompts, by default |
| Metrics | Is the system healthy now, and for whom? | p50 and p95 latency, error rate, refusal rate, cost per tenant | User ids as high-cardinality label values |
| Logs | What exactly happened in one request? | Structured events carrying the trace id | Copied secrets and full customer records |
| Audit record | Who is accountable for this action? | Caller, identity used, action, data classes, approval | Model reasoning treated as evidence of intent |
A trace is the spine. A metric without a trace can tell you that p95 doubled but not which tool did it. A log without a trace id is a needle you cannot search for.
Redaction applied in a dashboard protects the dashboard. Redaction applied before the network call protects every store downstream, including the observability vendor your security team never reviewed.
Use three tiers. Drop what you must never hold, such as secrets and full card numbers. Tokenise what you need to correlate, such as user and account identifiers. Keep what is already internal and necessary, such as record ids and trace ids.
import re
EMAIL = re.compile(r"[\w.+-]+@[\w-]+\.[\w.]+")
CARD = re.compile(r"\b(?:\d{4}[ -]?){3}\d{4}\b")
def redact(event, users):
"""Drop secrets, tokenise identities, keep what an incident needs."""
clean = dict(event)
clean.pop("session_token", None)
clean["user"] = users.setdefault(event["user"], "u-%04d" % (len(users) + 1))
clean["prompt"] = CARD.sub("[card]", EMAIL.sub("[email]", event["prompt"]))
return clean
users = {}
print(redact({"trace_id": "t-8f21", "user": "dana@example.com",
"session_token": "sk-live-abc",
"prompt": "Refund 4111 1111 1111 1111 for dana@example.com"}, users))Cost per request tells you very little. Cost per tenant, per feature and per tool call tells you which design decision to revisit.
A tool that returns 50 kilobytes per call shows up as token volume, not as a tool cost. Without attribution, the team blames the model and rewrites prompts, while a badly scoped tool keeps spending the budget.
Charge cost to the same unit you charge revenue or budget to. When a single feature owns 60% of spend, the review writes itself: check its context size, its tool results and its call pattern, in that order.
An alert should fire on a symptom a user or a budget owner would recognise. Central processing unit load is not a symptom. A refusal spike, a rising error rate, a p95 breach, a cost anomaly per tenant and an evaluation score drop are symptoms.
Every alert needs an owner and a first action. An alert without a runbook is a dashboard with a pager attached, and within a month the team will mute it.
The refund agent from the start of this lesson is going live. You have one sprint to make it operable.
A defensible pack uses trace id, span id, tool name, status and token count. It refuses to store session tokens, redacts at the emitter, alerts on refund amount deviation per tenant, and keeps the audit record under the retention rule your regulator requires.
Key takeaways
One trace id per request is the spine; metrics and logs are only useful when they join to it.
Four signals answer four questions: trace, metrics, logs and audit evidence.
Redact before the data leaves the request path, and test the redaction code like production code.
Attribute cost per tenant, per feature and per tool call, or the team will blame the model.
Alert on user-visible symptoms, with an owner and a first action for each alert.
Log the structure of a request, not its payload; fetch the payload from the system of record.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.