Verified against Langfuse · 2026-07-26
Define what your agent needs to log before you can debug it in production
A prompt for designing the trace and span schema for an agent pipeline — per-stage inputs, model versions, and outcomes, plus a sampling rule that never drops a failed request — written before the first production incident makes the logging gaps obvious the hard way.
The prompt
Ready to copy — highlighted parts are example details you can swap.
You are designing the observability and tracing schema for an agent pipeline, deciding exactly what gets logged at each stage before an incident forces you to add logging retroactively to a system nobody can currently explain the behavior of. PIPELINE STAGES query rewrite -> hybrid retrieval -> reranking -> generation -> citation mapping CURRENT LOGGING GAPS Currently only end-to-end latency and a final success/failure boolean are logged; when generation returns a wrong answer there's no way to tell if retrieval or the prompt was at fault — start from what's actually missing today, not a theoretical complete observability stack, since maximal logging that never gets used is its own cost. SPAN SCHEMA REQUIREMENTS For each stage, define a span with: - Inputs actually received — not "the prompt" as a blob, but the specific variables/parameters that went in, so a bad output can be traced back to a specific bad input. - The exact model/tool version invoked, since "the LLM said X" is useless for debugging a regression if you can't tell whether it was the old model version or the new one that said it. - Latency for that stage specifically, not just end-to-end — an end-to-end latency spike could be retrieval, generation, or a downstream tool call, and only per-stage timing tells you which. - Token counts, input and output, per LLM call, for cost attribution per stage, not just a total per request. - A stage-specific outcome field, such as chunks returned plus scores for retrieval or success/failure plus error for a tool call — not a generic "success: true/false" that can't distinguish a clean success from one that technically finished but returned something wrong. CORRELATION Every span for a single end-to-end request must share a UUID generated at the API gateway, propagated as a header through every internal service call, so a slow or wrong response can be reconstructed as one connected trace across every stage it touched, not scattered log lines with no way to associate them. PII AND RETENTION user question text and retrieved document excerpts are logged in full to a restricted, access-controlled trace store; the same fields are redacted to a hash in the general-purpose metrics store used for dashboards — state explicitly what gets redacted before it's written to logs versus what's needed in full for debugging and therefore has to live in a more restricted store with its own retention and access policy, rather than either logging everything raw or redacting so aggressively that debugging becomes impossible. SAMPLING 10% of successful requests sampled for full tracing; 100% of requests where generation's finish_reason is not 'stop', or where a stage returned an error — full tracing on every request if volume allows it; if not, state the sampling rate and, critically, whether failed or flagged requests are always fully traced regardless of the sampling rate. They should be — sampling should never be the reason a real incident has no trace. OUTPUT FORMAT 1. The span schema per stage, as field names and types. 2. The trace correlation strategy. 3. The PII redaction rule per field category. 4. The sampling rule, stated as a specific percentage plus the always-trace exceptions.
Customize
Optional — swap in your own details for the highlighted parts above.
Why this works
The reason to define a span per pipeline stage instead of one blob per request is that agent pipelines fail in the middle, not just at the edges, and a coarse trace can't localize which stage actually caused a bad output — a wrong answer could be a retrieval miss, a reranker that dropped the right chunk, or a generation step that ignored good context it was actually given, and these three failures require completely different fixes. Without per-stage spans, every debugging session starts by re-running the request manually with extra print statements added on the spot, which is the exact position a proper tracing schema exists to prevent — and it means every production incident takes longer to root-cause than the last one that happened to leave better breadcrumbs behind. The always-trace-on-failure exception to sampling matters because 'failure' for an LLM pipeline is broader than an HTTP error code. A generation call that gets truncated by hitting a token limit, or one that returns a finish_reason indicating a content-filter stop, looks like a completed, non-erroring request to any monitoring that only checks for exceptions — which means a sampling strategy that only guarantees tracing on hard errors will still miss the soft failures that produce a technically-200 response with a garbled or truncated answer. Tying the always-trace rule to output-quality signals like finish_reason, not just error status, is what actually catches the failure modes specific to LLM calls instead of only the failure modes borrowed from ordinary API monitoring. Splitting PII handling into a restricted full-fidelity trace store and a redacted general metrics store resolves a real tension instead of picking a side of it: aggressively redacting everything makes a system impossible to debug when the actual bug depends on exactly what a user asked or what text got retrieved, while logging raw user input and document content everywhere, including dashboards and alerting tools with broad internal access, creates a compliance and breach-surface problem that has nothing to do with debugging. Keeping the full-fidelity version narrowly accessible while still shipping useful, PII-safe signal to the tools the whole team can see is what makes both debugging and compliance actually achievable at once.
Verified against
Langfuse 3.2 · 2026-07-26
OpenTelemetry GenAI semantic conventions 1.2 · 2026-07-26
Changelog
- 2026-07-26 — Initial publish, verified against Langfuse 3.2 tracing and the OpenTelemetry GenAI semantic-conventions spec.
Building this for real?
This is a free starting point. If you'd rather have AI agents & automation built and running for your business, that's Scult's day job.
EXPLORE AI AGENTS & AUTOMATION
