Skip to content
ML Academy

LLMs, GenAI, RAG, agents, evaluation · insight-0662

Trace each LLM request as spans per stage with model, tokens and finish reason

Evidence type
documented fact
Difficulty
easy
Roles
ML engineer, Applied AI
Industries
cross-industry

Summary: situation, action, reason, boundary

  1. Situation

    A user reports a slow or wrong answer, and logs show only the final response and total latency.

  2. Action

    Emit one trace per request with child spans for retrieval, rerank, each model call and each tool call; record requested and responded model, input and output tokens, finish reason, document ids and config versions.

  3. Reason

    Stage-level spans turn a vague complaint into a located failure. OpenTelemetry's GenAI conventions standardise attributes such as request and response model, input token usage and finish reasons, so traces stay comparable across vendors.

  4. Boundary

    Production RAG and agent systems (day 52 core skill).

Symptom or risk

You cannot tell whether time and errors came from retrieval, reranking, the model call or a tool, or which model version answered.

Exceptions

One-off notebooks.

Trade-offs

Trace volume costs money; sample successful requests and keep all errors.

Pitfalls

Logging only the requested model alias, not the model version that actually responded.

Lessons and concepts

Claims and their sources