By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Logs are a flat stream of sentences. A trace is a tree with timing: the gateway span contains the retrieval span, the model span and the approval span, and each span carries the attributes that explain its share of the request. When p95 latency doubles, a log line tells you that the request was slow; a trace tells you that retrieval grew from 250 ms to 1,400 ms because the carrier policy index was rebuilt at 09:00.
For Waypoint, one trace per request is the rule, and every dependency gets one span. A trace is useful only if it can answer the questions the on-call engineer actually asks: which prompt version shipped, which model alias served, which tools were called with what arguments, how many tokens were spent, and who approved the chargeable action.
import json
from dataclasses import dataclass, field
@dataclass
class Span:
name: str
started_ms: int
ended_ms: int
attributes: dict = field(default_factory=dict)
@property
def duration_ms(self) -> int:
return self.ended_ms - self.started_ms
@dataclass
class Trace:
request_id: str
prompt_version: str
model_alias: str
spans: list[Span] = field(default_factory=list)
def finish(self) -> dict:
start = min(span.started_ms for span in self.spans)
end = max(span.ended_ms for span in self.spans)
return {
"request_id": self.request_id,
"prompt_version": self.prompt_version,
"model_alias": self.model_alias,
"duration_ms": end - start,
"spans": [
{
"name": span.name,
"duration_ms": span.duration_ms,
"attributes": span.attributes,
}
for span in self.spans
],
}
trace = Trace(
request_id="req_8f41c2",
prompt_version="wp-update@v7",
model_alias="waypoint-standard",
)
trace.spans.append(Span("gateway", 0, 1900, {"tenant": "northline"}))
trace.spans.append(
Span("retrieval", 40, 300, {"policy_version": "northline-policy@v3", "clauses": 2})
)
trace.spans.append(
Span("model", 320, 1750, {"input_tokens": 1240, "output_tokens": 260})
)
trace.spans.append(
Span("approval", 1780, 1900, {"action": "propose_reroute", "decision": "pending"})
)
report = trace.finish()
print(report["duration_ms"])
print([span["name"] for span in report["spans"]])
print(sum(span["attributes"].get("input_tokens", 0) for span in report["spans"]))| Field | Why it matters | Example |
|---|---|---|
request_id | Joins every log line, span and approval record for one request | req_8f41c2 |
prompt_version | Tells you which behaviour produced the answer | wp-update@v7 |
model_alias + resolved snapshot | Distinguishes an alias flip from a provider-side change | waypoint-standard → sim-2026-09-01 |
tool_calls | Shows what the model asked for and what was executed | search_carrier_policy, propose_reroute |
| Token usage | Explains cost and context growth per request | input 1240, output 260 |
| Stage latency | Attributes a slow request to one dependency | retrieval 260 ms, model 1430 ms |
approval | Proves whether a chargeable action waited for a human | pending, approved_by alice, rejected |
Each tool call is a child span with the tool name, a hash of the arguments (never the raw customer data), the outcome and the duration. If the model proposes a reroute, the trace should show the proposal, the approval id and the final execution attempt as separate spans. That separation is what lets you answer the worst question in an incident: was the refund executed once, twice or not at all?
Key takeaways
A trace is a timed tree of spans; a log line cannot attribute latency or cost to a dependency.
Every request gets one trace with spans for gateway, retrieval, model, tools and approval.
Record request ID, prompt version, model alias, tool calls, token usage and approval state.
Keep raw customer data and full prompts out of span attributes by default.
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.