Use when an agent harness needs operational visibility — token spend per turn/session, latency breakdown, tool-call success rates, and the ability to replay/debug a specific run. Apply when designing the observability layer for production agents. Covers span trees (turn → tool-call → subagent), token/cost attribution, structured logging, replay format, and the difference between eval (quality) and telemetry (ops).
Instalação
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Use when an agent harness needs operational visibility — token spend per turn/session, latency breakdown, tool-call success rates, and the ability to replay/debug a specific run. Apply when designing the observability layer for production agents. Covers span trees (turn → tool-call → subagent), token/cost attribution, structured logging, replay format, and the difference between eval (quality) and telemetry (ops).
Telemetry & Tracing
Pain Signals — You Need This Pattern When:
A user reports "the agent was slow" and you cannot identify which turn or tool was the bottleneck
Cost per session is high and you cannot attribute it to specific behaviors (verbose retries? wrong model? cache miss?)
A bad run cannot be reproduced because the inputs are not recorded
Tool failures are invisible until users complain
Cache hit rate dropped after a deploy and you noticed three weeks later
You ship a prompt change and cannot tell whether quality regressed
Telemetry is for operations: latency, cost, errors, throughput. Quality is the eval-harness skill's job. Both are required; neither replaces the other.
Core Principle
Sessions are trees of spans. Each span has a start, end, attributes, and parent. Costs and latencies aggregate up the tree. Logs attach to spans. Replays read the tree.
Single API request; tokens in/out, cache, model id, $, ttft
tool_call
One tool invocation; tool name, args summary, result size, exit
subagent
Subagent run; nested session-tree as child spans
hook
Hook execution; name, decision, latency
compact
Compaction event; before/after token counts
Span granularity is a tradeoff: fine spans give detail and cost storage; coarse spans miss the data you need to debug. Default fine inside dev/staging, sample in production.
Production traces are expensive to store at full fidelity.
Strategy
When
Head-based (decide at session start)
Simple; misses interesting tails
Tail-based (decide at session end based on outcome)
Keeps errors, slow runs, expensive runs
Always-sample errors and high-cost
Default in production
Always-sample in dev/staging
Default outside production
Tail-based sampling for errors + p99 latency + p99 cost catches almost everything operationally interesting at low storage cost.
Telemetry vs Eval-Harness
Both produce metrics. Different concerns:
Telemetry
Eval-Harness
Question
Is the system healthy?
Is the system correct?
Time horizon
Live, last-N-minutes
Per release, dataset-driven
Inputs
Production traffic
Curated datasets
Metrics
Latency, cost, error rate, throughput
Accuracy, quality scores, regression vs baseline
Ownership
SRE / harness ops
ML / product
Don't conflate. A telemetry dashboard that says "all green" while eval shows quality regression is consistent — and dangerous if you watch only one.
Replay From Trace
A complete trace is a replay artifact. Operators reconstruct sessions by reading the span tree.
To make traces replayable, attach to each span:
Inputs (full prompt for model_call, full args for tool_call)
Outputs (full response, full tool result)
Non-determinism (model temperature, randomness seed if any)
Replay then becomes: "For each span, replace 'execute' with 'read recorded output.'" Pairs naturally with session-persistence's event log — telemetry is a query layer over the same data.
PII handling: if traces contain user data, redaction at write or field-level encryption is mandatory. Don't ship traces to a third-party APM with secrets in them.
Dashboards
Minimum dashboards for a production agent harness:
Cost — $ per session p50/p95/p99, $ by model, cache savings, top expensive sessions