# What Is Tracing for LLM Apps?

> What a trace and a span are, what gets recorded, and how to use one to find why an AI answer was wrong or slow, for your AI interview.

**In short:** Tracing for LLM apps records each step of one request, such as each model call, tool call and document search, with its inputs, outputs and timing. The steps for one request form a trace, which shows why an answer was wrong or slow.

AI and LLM interview question Q260, Evaluation and observability. Intermediate, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-tracing-for-llm-apps

## Say it in 30 seconds

Tracing is a logbook for one AI request. It records each step: every model call, tool call and document search, with what went in, what came out and how long it took. Those steps form a trace. When a claim takes 33 seconds, or an answer goes wrong, the trace shows which step caused it. I also keep personal data out of traces, because they can hold user prompts.

## Say it in 2 minutes

An AI app works in steps. It may search a document, call a model, call a tool such as a policy lookup, then call the model again to write the reply. Tracing records each step as it happens. Each record keeps what went in, what came out and how long it took. LangSmith calls each step a run, and the steps for one request together form a trace.

Take a claims triage agent at a mid-size insurer that suddenly takes 33 seconds on one claim. The final text looks fine, so it tells me nothing. The trace shows a policy lookup timing out after 30 seconds, then retrying. That is where the time went. The fix is a shorter timeout with a fallback path, and the model stays as it is.

Tracing has a privacy cost. Traces can capture user prompts and responses, so I redact personal fields before they are logged and limit who can read the traces. Extra pricing can also apply, so I keep the detail that helps debugging and set how long it stays.

Tracing shows what happened. Whether an answer was right needs an evaluation, so I pair traces with evaluations that score the answers.

## What is tracing, in plain words?

A trace is a logbook for one AI request. The AI is usually a large language model (LLM), the kind of model that writes and reads text. The trace lists each step the app took to answer it: every model call, every tool it used, every document it searched, and how long each step took.

Think of the chart a hospital nurse keeps for one patient. Each test, drug and visit goes on it with a time, so anyone can see what happened and in what order. Tracing does the same for an AI request.

Here is a realistic case. A claims triage agent at a mid-size insurer takes 33 seconds to handle one claim. The final text looks fine, so the text alone tells you nothing. The trace shows where those seconds went.

- **Trace:** All the recorded steps for one request, grouped under one trace ID.
- **Span:** One timed step inside a trace, such as one model call.
- **Run:** LangSmith's name for a step. It works like a span.
- **Tool call:** The model asking your code to run a function, such as a policy lookup.

## What does a trace record?

Microsoft's Foundry docs say tracing records information such as the user's inputs and prompts, the agent and model inputs and outputs, and the tool calls and intermediate steps.

- **Inputs and outputs:** What went into each model call and tool call, and what came back.
- **Tool calls:** Which tools ran, with what arguments, and what they returned.
- **Timing:** When each step started and ended, and how long it took.
- **Cost and errors:** Token usage (the pieces of text the model counted) and any errors.

That detail is also the risk, covered further down. A trace with a full prompt is a copy of the user's data.

## How do runs, spans and traces fit together?

A step is called a run in LangSmith and a span in OpenTelemetry, the standards that Microsoft says its tracing is built on. A trace groups the steps for one request. LangSmith and Microsoft put it like this:

> "A trace is a collection of runs for a single operation." (LangSmith)
>
> "Distributed tracing captures the execution flow of AI applications, providing visibility into LLM calls, tool invocations, agent decisions, and inter-service dependencies." (Microsoft)

*Diagram, How one request becomes one trace: One customer request reaches the claims agent. Each model call and tool call is recorded as a span under that request. All of them are saved together as one trace, so the slow policy lookup stands out.*
1. The claim reaches the agent as one request.
2. The agent records each step it takes as a span.
3. All the spans are saved together as one trace.

Here is the same idea in a few lines of plain Python. Each step is a span, and a span nests under the step that called it.

```python
# A tiny tracer: each step is a span, and a span nests under the step that called it.
# The timings are made-up numbers, so the output is the same on every run.
spans = []

def span(name, ms, parent=None):
    spans.append({"name": name, "ms": ms, "parent": parent})
    return len(spans) - 1

def show(i, depth=0):
    s = spans[i]
    print("  " * depth + f"{s['name']} ({s['ms']} ms)")
    for j, child in enumerate(spans):
        if child["parent"] == i:
            show(j, depth + 1)

run = span("claim_agent", 33050)
span("model_call: plan the check", 850, run)
tool = span("tool: policy_lookup", 31000, run)
span("api_timeout", 30000, tool)
span("retry", 1000, tool)
span("model_call: write reply", 1200, run)
show(run)
```

Output:

```text
claim_agent (33050 ms)
  model_call: plan the check (850 ms)
  tool: policy_lookup (31000 ms)
    api_timeout (30000 ms)
    retry (1000 ms)
  model_call: write reply (1200 ms)
```

Read the output as a tree. The policy lookup has a 30-second timeout and a 1-second retry under it, so the tool is where the time went. OpenAI's Agents SDK docs describe the same shape: a trace is an end-to-end operation made of spans, and each span has a start and an end time.

> **Tip:** If asked to define a trace, say what it is and give one example from a real app, such as a claim that took too long. Then say spans are the steps inside it.

## What does tracing cost you, and what must you protect?

Microsoft's Foundry docs say tracing is off by default, and that it can capture personal data, including user prompts and responses. Once you turn it on, traces can hold your users' data.

OpenAI's Agents SDK has tracing enabled by default. Its docs say the spans for model calls and function calls store inputs and outputs, and that these may contain sensitive data, so you can disable capturing that data.

- **Too little: Only the final reply.** You cannot see which step failed, or why.
- **Right amount: Every step, timed.** Each step has timing and inputs, with personal fields redacted and read access limited.

Microsoft says to redact or minimise personal data before it is logged, and to apply access controls and retention policies to trace data. It also notes that extra pricing might apply for Azure Monitor App Insights, its logging service.

### How would you find out why a claim took 33 seconds?

Start with the trace for that one claim. Then follow the steps.

*Diagram, From a slow answer to a fix: The final text looks fine, so open the trace for that claim. The policy lookup is the widest step, and its timeout and retry show why. Shortening the timeout cuts the long wait, and the same claim is run again to check.*
1. Open the trace for that one claim.
2. The policy lookup stands out, and its timeout explains the wait.
3. Shorten the timeout and add a fallback, then test the same claim.

1. **Find the trace by its ID:** Every run in one trace is tied to one trace ID, so a single lookup gets the whole path.
2. **Sort by time:** Look for the widest step. Here the policy lookup took 31 seconds, far more than the 850 ms model call.
3. **Check its children:** The 30-second timeout and the 1-second retry sit under the tool, so the fault is in the tool, not the model.
4. **Fix and test again:** Shorten the timeout, add a fallback path, then run the same claim again and read the new trace.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a trace is the record of one request, made of timed steps.
- [ ] Trace, span and run, and how they nest.
- [ ] What gets recorded: inputs, outputs, tool calls and timings.
- [ ] Why it beats reading the final answer: you see which step failed.
- [ ] The privacy cost: traces can hold personal data, so redact and limit access.
- [ ] Tracing shows what happened. Evaluation scores whether it was right.

**Common traps**

- Trap: "Reading the final answer is enough." Better: The final answer hides the failing step. A trace shows each model call, tool call and search in order.
- Trap: "Tracing is just logging, so turn on everything." Better: Traces can hold personal data. Capture what you need, redact personal fields, and limit who can read them.
- Trap: "A trace shows whether the answer is correct." Better: A trace shows what happened. Whether an answer is right needs an evaluation that scores it.

## Can you spot the problem in a trace?

**Spot the risk:** Your support bot saves every trace. Which span needs fixing before launch?

A. retrieve_policy: 210 ms, returned 3 documents
B. model_call: 1.1 s, 2,340 tokens in, 180 out
C. lookup_customer(name=Asha Patel, card_number=full 16 digits)
D. guard_check: 4 ms, allowed

**Answer:** C. The third span saves a full card number inside the trace, so anyone who can read traces can read it. Redact personal fields before they are logged, and limit who can read them.

**Quick check:** A bank's fee bot quoted an old card fee. Which record shows why?

A. Only the final reply the customer saw
B. The model's final reply with its token count
C. A trace with each document search, what it returned, and each model call
D. The number of chats opened today

**Answer:** C. The trace shows which document the bot searched and what it returned, such as an old fee table. The model call shows how it used that text. The other records hide the cause.

## Can you answer these from memory?

**Flash cards**

- **What is tracing?** A record of every step in one AI request, with inputs, outputs and timing.
- **Trace or span?** The trace is the whole request. A span (LangSmith: a run) is one timed step in it.
- **What does a trace show?** Model calls, tool calls, document searches, what went in and out, and how long each took.
- **Biggest risk?** Traces can hold personal data. Redact it and limit who can read them.
- **Is tracing on by default?** Microsoft Foundry: off. OpenAI's Agents SDK: on, and it can be turned off.
- **Tracing or evaluation?** Tracing shows what happened. Evaluation scores whether the answer was right.

## Likely follow-up questions

- Q247 Offline vs online evaluation? https://designervenkat.online/interview/ai/offline-vs-online-evaluation
- Q246 How do you know your AI system actually works? https://designervenkat.online/interview/ai/how-to-know-your-ai-system-works
- Q259 Which production metrics matter for a chatbot? https://designervenkat.online/interview/ai/production-metrics-for-a-chatbot
- Q261 How do you detect drift? https://designervenkat.online/interview/ai/how-do-you-detect-drift
- Q262 "The model got worse after an upgrade." What do you do? https://designervenkat.online/interview/ai/the-model-got-worse-after-an-upgrade-what-do-you-do
- Q257 How do you regression-test prompts? https://designervenkat.online/interview/ai/how-to-regression-test-prompts

## Learn it in depth

- [Tracing and logging](https://designervenkat.online/learn/ai-engineering/tracing-and-logging)
- [Seeing inside your AI app](https://designervenkat.online/learn/ai-engineering/llm-observability)
