Chapter D · 4 of 4~10 min

LLM tracing lab

Log **spans** per request — embed, retrieve, generate — so you debug production RAG without guessing.

Reviewed July 2026 · interactive lab

Paths & resources for this lesson

1Try it yourself

Playground

Trace a failed RAG answer

Open spans in order — find where quality broke before blaming the model.

    2Read & reflect

    Recap

    #What you just did

    You opened spans in order and found 0 retrieval chunks before blaming the generator.

    Read

    #What to trace

    | Span | Log | |------|-----| | embed_query | latency, model version | | retrieve | chunk IDs, scores, count | | generate | tokens, finish reason | | tool_call | name, args (redacted) |

    Read

    #Redaction rules

    • Never log raw API keys or full PII
    • Hash user IDs if needed for correlation

    Read

    #Try it

    Add a request ID header and pass it through every LLM + vector call in one route.

    3Spark check

    Continue learning · glossary & guides