List the trace spans a context engineering pipeline should emit per call
Emit one span per stage (retrieve, rerank, assemble, generate, post-process), each carrying the artifact and the timing, all sharing one trace_id so you can replay the exact prompt that produced any output.
Imagine a chef in a busy kitchen and a customer who hated their meal. If the chef kept no notes, you can only ask, was it the ingredients, the prep, the cooking, the plating, or something the server did at the table? You cannot tell. Now imagine the kitchen logs each step: which tomatoes came out of the crate, how long they were prepped, what temperature the pan was, when the plate left the pass, how the server presented it. The same complaint becomes a five-minute investigation instead of a guessing game. Tracing spans do this for an LLM pipeline. Every stage writes a log, every log shares one ticket number, and a bad output is traceable end to end.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
A context-engineering pipeline is a small distributed system inside one request. Retrieval calls a vector index. Rerank calls a cross-encoder. Assembly stitches a prompt out of the survivors. Generation calls the LLM. Post-processing validates the structured output. Each stage has its own latency curve, its own failure modes, and its own surface area for regressions.
When something goes wrong in production, you have one of two situations. Either you instrumented the pipeline and you can walk a chain of spans to find the stage that drifted, or you did not and you are doing forensic archaeology on a single output. The first situation costs a few minutes of operator time. The second is open-ended.
This card is the case for the first situation. Five spans, one trace_id, deliberate artifact capture.
The five spans and what each one carries
Production traces in 2026 converge on roughly the same shape. Names vary by framework but the structure is consistent.
- retrieve: candidate chunk ids, similarity scores, query embedding hash, index version, ANN latency. This span tells you whether recall is the problem (the right chunk was not even in the pool).
- rerank: input rank, output rank, score per chunk, reranker model version, batch size, latency. This tells you whether the reranker is helping or hurting and lets you detect drift when a reranker is upgraded.
- assemble: the final ordered chunk list with byte count, token count, and role marker per slot; the prompt template version; the total prompt token count. This is the load-bearing span: it is what lets you reproduce the exact prompt offline.
- generate: model id, sampling parameters, input and output token counts, finish reason, cache hit ratio, end to end latency. This connects the output to the model state that produced it.
- post-process: schema validation result, repair retries used, final structured output.
The artifact, not just the timing
The trap is logging only durations and skipping the artifacts. Latency alone tells you a span was slow, not what it contained. You need the per-stage payload to localize a quality regression.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- LangSmith ships span types that map cleanly to retrieve, rerank, generate and is the default tracing layer for LangGraph and LangChain pipelines.
- Arize Phoenix is an open-source tracing UI that natively understands OpenTelemetry LLM semantic conventions and surfaces per-span artifacts.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you redact PII from spans without losing reproducibility?
Hash sensitive fields with a stable salt and store the hash plus length; combined with the prompt template you can still reproduce structure without the literal user data.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Logging only the final prompt and the final answer. You can see the failure but you cannot tell which stage caused it; retrieve, rerank, and assemble each have to emit their own span.
60 second bullets to scan on the way to the call.
What are the five spans and what artifact does each carry?
Why is the assemble span the most important?
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.