Trace Agent Turns and Tool Runs with Cloudflare Agents Tracing
Use the official Tracing docs to locate model, tool and approval spans in one Agent turn and limit what payloads are recorded.
Prerequisites and input · Engineering checks · 1. Enable traces in the Wrangler configuration
At a glance
When an agent behaves unexpectedly or runs slowly, you need to see what its model calls, tool runs and approvals did during a specific turn. This guide takes one event you want to locate and arranges the trace and span structure, identity fields and payload-recording switches from the Cloudflare Agents Tracing documentation into an observation plan. Each step says where to work, what to look at and when to stop.
Runtime and applicability
- Article type
- Engineering practice
- Verified
- Applies to
- Cloudflare Agents SDK Trace Agent Turns and Tool Runs with Cloudflare Agents Tracing
Execution locations and responsibilities
- Cloudflare Agent server and connected client Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.
When to use
- Each turn produces one trace made of spans.
invoke_agentcovers the whole turn,chatis a model call,execute_toolis a tool run, andtool_approvalnests under the tool span. Subagent work appears under the operation that invoked it. First decide which span the event should appear in, then check whether it does. The docs note that approval spans represent lifecycle events within one Worker invocation and do not measure how long a person waits across invocations.
When not to use
- This guide covers tracing and observation only. State sync, scheduled work, queues and route authentication belong to other tasks and are not expanded here.
tool_approvalcannot measure how long a person takes to approve; waits spanning several Worker invocations need another record.- Do not treat traces as a full conversation archive. The docs say payloads may be truncated and images are not shown in Session replay.
- The docs state Workers does not yet support the OpenTelemetry API directly, so a custom harness must create spans by hand with the Workers custom spans API.
Prerequisites and input
- You have picked one Agent event or tool call to locate and can say which session and turn it belongs to.
- You can edit the Worker's Wrangler configuration and open the Agents tab in the Cloudflare Dashboard.
- You know whether the agent uses Think, Flue, direct AI SDK calls or a custom harness, because tracing setup differs for each.
- Automatic Flue instrumentation follows the v2+ documentation scope; check compatibility before using other versions.
Engineering checks
Check whether the span lifecycles match — Each turn produces one trace made of spans. invoke_agent covers the whole turn, chat is a model call, execute_tool is a tool run, and tool_approval nests under the tool span. Subagent work appears under the operation that invoked it. First decide which span the event should appear in, then check whether it does. The docs note that approval spans represent lifecycle events within one Worker invocation and do not measure how long a person waits across invocations.
Check whether the identity fields are stable — The dashboard groups work by Agent name, Agent ID and Conversation ID. The agent name should be a shared logical name and must not be derived from a request, conversation or user identifier, which creates too many distinct names. Think can infer identity from the Agent instance. Direct AI SDK calls have no instance, so identity must be supplied on each call. A custom harness must write gen_ai.agent.name, gen_ai.agent.id and gen_ai.conversation.id on both invoke_agent and chat spans.
Check whether the payload scope is deliberately limited — Message and tool payloads can contain personally identifiable information, so record only what is safe to store. Think and wrapAISDK() store nothing by default. storeMessages controls input and output messages on chat spans, and storeTools controls arguments and results on execute_tool spans. Flue v2+ stores content by default and stops only when content is set to false. Custom spans need payload attributes added by hand and are recorded whenever the invocation is sampled. Payloads are also subject to span size limits and may be truncated.
1. Enable traces in the Wrangler configuration
Where: the Agent Worker Wrangler configuration. Input: its current configuration and integration plan. Set observability.traces.enabled=true and save it; complete integration, identity and payload scope before deploying and checking the Dashboard. Completion: tracing configuration agrees with the integration plan. Stop to locate the configuration if unclear, rather than requiring Dashboard visibility before setup is complete.
2. Confirm the integration and who owns tracing
Where: the agent's server code. Input: the agent class and how it calls models. Action: Think and Flue v2+ instrument turns automatically. For direct AI SDK calls, wrap the namespace once with wrapAISDK(), which the docs say supports AI SDK v6 and v7. Anything else uses the Workers custom spans API to build spans manually. A Durable Object that installs the Lifecycle directly gets no agent spans from the Lifecycle itself, so it needs one of the latter two approaches. Completion check: you can write down which case applies and what creates invoke_agent. Stop condition: if ownership is unclear, pause, because every later field depends on it.
3. Set and verify identity fields
Where: the agent class, each AI SDK call, or custom span attributes. Input: a shared agent name, a stable agent ID and a conversation identifier. Action: with direct AI SDK use, v7 supplies identity through runtimeContext and the functionId field under telemetry, while v6 supplies Agent name with experimental_telemetry.functionId and agentId plus conversationId with experimental_telemetry.metadata. The docs map these to gen_ai.agent.name, gen_ai.agent.id and gen_ai.conversation.id. Extra scalar context such as a tenant or route can make traces easier to query, but must not include credentials, tokens or user input. Completion check: the configured agent name is fixed and the agent/conversation ID origins are explicit; actual grouping is checked after deployment. Stop condition: if the name varies per request or user, fix it to a constant first.
4. Decide the payload recording scope
Where: Think class properties, the options passed to wrapAISDK(), Flue v2+'s tracing setup, or custom span attributes. Input: whether the event really needs message or tool arguments. Action: leave default-off integrations off, and turn on storeMessages or storeTools only when needed and the data is safe. If Flue v2+ should not keep content, set content to false. For custom spans, add payload attributes only when safe, serializing structured values into scalars first. Completion check: you can state which spans record what and which do not. Stop condition: if you cannot confirm that payloads are free of personal information, keep recording off and locate the problem from timing and status alone.
5. Reproduce one turn and compare Session replay with Trace
Where: the Agents tab of the Dashboard, with the agent selected. Input: one identifiable session and a specific turn. Action: after completing the preceding configuration, integration, identity and payload scope, deploy through the existing process and confirm Dashboard visibility and identity grouping. If absent, inspect integration, identity and sampling. In Session replay read the messages, reasoning, tool calls and subagent activity across turns. In the Trace waterfall read each operation's start time, duration and caller for that turn. Check for invoke_agent, chat, execute_tool and tool_approval. Completion check: the event maps to a specific span, or you have confirmed it is missing. Stop condition: stop once you find the span and a cause. If it is missing, go back and recheck the integration and sampling instead of guessing.
6. Record the conclusion and the limits of the evidence
Where: your own investigation notes. Input: the spans, statuses and durations you read. Action: write the conclusion and note the documented limits. Traces are for debugging and observability, not a complete or lossless record. Long messages, reasoning, tool arguments and results may be truncated. Session replay does not display images. tool_approval excludes human waiting time. For outside analysis, the docs point to OpenTelemetry export in Workers Observability. Completion check: every conclusion names the span it rests on and its limits. Stop condition: if the evidence is truncated or missing, write undetermined and stop.
Task example
This is a synthetic manual walkthrough. Every expected observation is derived from the documentation and has not been verified. Suppose a booking agent takes a long time to answer after looking up available slots. You confirm it uses Think, so no extra instrumentation is needed, and you keep the default of not storing payloads. In the Agents tab you select the agent, find the turn in Session replay, then switch to Trace. You expect one chat and one execute_tool under invoke_agent, with the tool span taking most of the time, which points you at what the tool calls internally. If the tool also required approval, you would expect a tool_approval span beneath it, though it would not show when the user clicked confirm. Because storeTools is off, arguments and results are not visible, so you note that time concentrates in that tool and decide whether to turn the option on after confirming the data is safe.
Completion checks
- The event maps to a specific
invoke_agent,chat,execute_toolortool_approvalspan, or its absence is explicitly recorded. - The agent name is a shared logical name, the agent ID is stable, the conversation ID separates dialogues, and no name is derived from users or requests.
- Each payload option that was turned on has a recorded reason it is safe, options left off are noted, and truncation and sampling limits are acknowledged.
Verification scope
Only the official Cloudflare Agents Tracing documentation was read. Installation, login, API execution and output were not tested, and the observations in the example are hypothetical. The docs say agent traces count toward account-level ingestion and storage usage from December 1, 2026, with seven-day retention. This guide gives no prices, so check the official pricing page.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.