Two OpenTelemetry span types, invoke_agent and execute_tool, turned a Grok agent's separate model-call traces into one trace per question in Splunk APM: every model call and tool call as a step, and the task's total tokens and billed cost on top. That one view is where I could see the agent's tokens pile up: one question took 4 or 5 calls, and the prompt grew with every one.

Second run, task 1 in Splunk APM: one trace, every model call and tool call as a step.
The question was a small on-call puzzle: "We sold 200 orders today, but the sales dashboard shows 400. Find out why." All 8 of the agent's answers named the same cause from its tools: a 09:12 checkout deploy made the order webhook retry every delivery, so each order counted twice.
One cause reported in agent tools for the "burning tokens" people describe is what this lab shows too: the conversation is resent on every call, and a large tool result joins it.
TL;DR
- One agent question became 4 or 5 model calls, and every call resends the conversation so far.
- In every task, the last call's prompt was 2.91× to 2.92× the first. 58.3% of all prompt tokens had already been sent once (the same in both runs).
- An
invoke_agentspan around the task and anexecute_toolspan around each tool call made each question one trace. The app adds up xAI's usage onto theinvoke_agentspan, and Splunk APM kept those totals intact for all 4 tasks, with all 16 tool calls as spans.
In plain words
- An AI agent lets a model call tools in a loop: the model asks for a tool, the app runs it and sends back the result, until the model can answer.
- Tokens are what xAI's usage report counts for every call: prompt, cached, completion and reasoning tokens. Cached tokens are the part of the prompt xAI reports as served from its prompt cache.
- A trace records one request; each step in it is a span. Splunk APM is where they land.
What I tested
A Python pod on EKS ran the agent with grok-4.7 (reasoning effort low) and three tools with fixed data: an order count, today's deploys, and the order webhook's log. The OpenTelemetry OpenAI instrumentation (opentelemetry-instrumentation-openai-v2) traced every model call into Splunk APM through the Splunk OTel Collector. Each task started with its own ticket ID, so no task could reuse another task's messages. Two runs of 4 tasks: the instrumentation only, then with the agent spans.
What you'll see: every call bigger than the last
Here is the first run's first task, call by call, as xAI reported it:
| Call | Prompt tokens | Cached | New | Completion + reasoning | Tool it asked for | Billed (ticks) |
|---|---|---|---|---|---|---|
| 1 | 1,471 | 1,152 | 319 | 13 + 32 | get_order_count | 14,840,000 |
| 2 | 1,542 | 1,152 | 390 | 13 + 11 | get_order_count | 15,000,000 |
| 3 | 1,592 | 1,152 | 440 | 11 + 15 | list_recent_deploys | 16,120,000 |
| 4 | 1,779 | 1,536 | 243 | 13 + 41 | get_webhook_log | 15,780,000 |
| 5 | 4,284 | 1,664 | 2,620 | 38 + 63 | (answer) | 66,780,000 |
The lab's log puts this task at $0.012852 billed. Call 5 was 66,780,000 of its 128,520,000 ticks.
All 8 tasks looked alike: 4 or 5 calls, 4 tool calls, $0.011 to $0.0129 each, about $11.90 per 1,000 tasks. In the 4-call tasks, Grok asked for both order counts in one step, despite the one-tool-at-a-time instruction.
Where the tokens go
The model keeps no memory between calls. Each call sends the whole conversation again: instructions, question, earlier answers and tool results. In both runs, 58.3% of all prompt tokens had already been sent in an earlier call of the same task.
The prompt cache softens it. xAI reported 65.7% of all prompt tokens as cached in each run: 27,008 cached tokens out of 41,095 in the first and 41,123 in the second. The same cached total appeared in both runs; per task it differed. Even each task's first call had 1,152 cached tokens, though every task started with a fresh ticket ID. My guess is that this is something xAI places ahead of the messages, such as the tool definitions; I didn't test that.
The jump lines up with new tokens. After the webhook log came back, the first run's next call carried 2,611 to 2,623 new, uncached tokens. In the first task, that last call's 66,780,000 ticks were more than calls 1 to 4 together. Its output stayed small (38 completion and 63 reasoning tokens in the first task), so in this lab the jump in billed ticks came with the new input. On average the last call cost 4.45× the first in the first run and 4.42× in the second. The tools were local functions with fixed data; in this lab, the bill grew after a tool dropped a big result into the conversation.
xAI also counts reasoning apart from completion tokens: call 1 had 13 completion and 32 reasoning, and its chat span's output_tokens shows the 13.
What the instrumentation shows on its own
The instrumentation gives every model call a chat span with its tokens: the per-call view you need. With no span around the loop, each chat call starts its own trace, as you'd expect, so the first run's 4 tasks showed up as 19 traces.

Splunk APM: the second run's 4 tasks on top, the first run's single-call traces below.
One trace per task: add the OpenTelemetry invoke_agent and execute_tool spans
The GenAI agent conventions define an invoke_agent span for the task and an execute_tool span per tool call. The instrumentation's chat spans then sit under the task:
def agent_span():
return tracer.start_as_current_span(f"invoke_agent {AGENT}", kind=SpanKind.INTERNAL, attributes={
"gen_ai.operation.name": "invoke_agent", "gen_ai.agent.name": AGENT, "gen_ai.provider.name": "x_ai",
"gen_ai.request.model": MODEL})
def tool_span(name, call_id, step):
return tracer.start_as_current_span(f"execute_tool {name}", kind=SpanKind.INTERNAL, attributes={
"gen_ai.operation.name": "execute_tool", "gen_ai.tool.name": name, "gen_ai.tool.call.id": call_id,
"gen_ai.tool.type": "function", "lab.step": step})
When the task ends, its totals go on the task's span:
aspan.set_attribute("gen_ai.usage.input_tokens", tot["prompt"])
aspan.set_attribute("gen_ai.usage.output_tokens", tot["billed_out"])
aspan.set_attribute("gen_ai.usage.cache_read.input_tokens", tot["cached"])
aspan.set_attribute("xai.usage.cost_usd", tot["ticks"] / TICKS_PER_USD)
xai.usage.cost_usd is my own name for xAI's billed cost, from the cost_in_usd_ticks field described in xAI's cost tracking docs; the gen_ai.* names are OpenTelemetry's.
Read back from Splunk APM: 4 tasks, 4 traces, all 16 tool calls as execute_tool spans, and the totals the app set on every root span arrived intact.

Second run, task 1: its totals on the root span. Its prompts match the first run's task 1 call for call (10,668 tokens), but more was cached (7,040 against 6,656), so the bill differs.

Second run, task 1: billed cost.
Open the last chat span in the same trace (second run, task 1) and you see the jump: 4,284 input tokens, where the run's first calls averaged 1,470.3.

The answer call, after the webhook log joined the conversation.
Before you build a dashboard on this: input and cached tokens repeat between the root and its chat spans, so sum one span type, never all spans. For output, each chat span reports xAI's completion tokens as output_tokens, and xAI reports reasoning separately, so the lab sets the root's output_tokens to the task's completion plus reasoning tokens across all its calls (93 + 164 = 257 for this task). The xAI console's request log for the lab key is one more place to look.

xAI's log for the lab key, second run.
Try it yourself
EKS 1.34 on one t3.large node, Splunk OTel Collector chart 0.163.1, Python 3.13 with openai 3.60.0 and opentelemetry-instrumentation-openai-v2 2.4b0:
git clone https://github.com/Abhimanyu9988/showmerit
cd showmerit/labs/see-where-an-ai-agent-s-tokens-go-every-grok-step-in-one
export SPLUNK_REALM=us1 SPLUNK_ACCESS_TOKEN=... SPLUNK_API_TOKEN=...
export LAB_NAME=agent-lab AWS_REGION=eu-central-1
export XAI_API_KEY=... # a key with a spend cap
terraform init && terraform apply -var lab_name=agent-lab
./reproduce.sh # the instrumentation only
./fix.sh # the agent and tool spans, then every trace read back from Splunk APM
./cleanup.sh && terraform destroy -var lab_name=agent-lab
My run's 38 Grok calls were billed under ten cents. The raw output is in the lab's evidence folder.
What I didn't test
- A bigger agent: mine has three tools and fixed data.
- Trimming the webhook log, the obvious next step.
- Other models or reasoning efforts.
Every file in this lab
Everything above runs from these files. Open any of them to copy it, or clone the repo as shown:
README.mdcheck.shcleanup.shfix.shk8s/10-app.yamlk8s/11-telemetry.yamlk8s/12-tools.yamlk8s/20-agent.yamllib.shmain.tfmetrics.shproviders.tfreproduce.shsplunk.shevidence/: the raw output of my run
Sources
- Semantic conventions for GenAI agent and framework spans (OpenTelemetry)
- Function calling (xAI docs)
- Cost tracking (xAI docs)
- opentelemetry-instrumentation-openai-v2 (PyPI)
- Monitor LLM and agent performance with AI Agent Monitoring in Splunk Observability Cloud (Splunk blog)
Disclosure: I work at Splunk, part of Cisco. This is my personal blog; the post isn't sponsored or reviewed by my employer.
I reproduced this in a disposable AWS lab. The lab code and raw output are in the repo. Drafted with AI assistance and reviewed by me.