WorkflowAgent emits no tool-call telemetry inside a workflow (model calls fixed in #22378, tools still missing)
Description
#22378 fixed model-call telemetry for WorkflowAgent: model-call-telemetry.ts now dispatches the model call's lifecycle from inside the model step, where globally registered integrations are visible. Tool calls have the same gap and were not covered.
executeToolWithCallbacks in workflow-agent.ts calls telemetryDispatcher.onToolExecutionStart, executeTool and onToolExecutionEnd from the workflow body. The body cannot see AI_SDK_TELEMETRY_INTEGRATIONS, so the dispatcher is a no-op there. With registerTelemetry(new OpenTelemetry()) in instrumentation.ts, a durable WorkflowAgent run exports chat spans for every model call and no execute_tool spans for any tool call. A plain streamText in the same process exports both.
Versions: @ai-sdk/[email protected] (also checked against main), [email protected], @ai-sdk/[email protected], [email protected].
Reproduction
Same harness as #22378, with one tool on the agent:
export async function agentWithTool(prompt: string) {
'use workflow';
const agent = new WorkflowAgent({
model: fakeModel, // first call returns a tool call to `echo`, second returns text
tools: { echo: tool({ inputSchema: z.object({ text: z.string() }), execute: echoStep }) },
});
return agent.stream({ prompt, writable: getWritable() });
}
async function echoStep({ text }: { text: string }) {
'use step';
return text;
}
With an OpenTelemetry integration registered globally:
- Expected: a
chatspan per model call and anexecute_tool echospan for the tool call. - Actual: the
chatspans arrive; no tool span, andonToolExecutionStart/onToolExecutionEndon the integration are never called.
Notes
- Tool
executefunctions are commonly'use step'functions, so the fix probably can't wrap execution in a library step. A step that dispatches start/end after the tool returns would work, if it carries the measured start time and duration rather than stamping the span when it runs. - Today we rebuild tool spans from the turn's saved output when the turn ends. That loses real timings, shows a running turn with no tools, and doesn't cover agents run outside our chat path.
Identify issue type
Identified as Bug
Confidence: High
Rationale
This reports a concrete telemetry failure in existing WorkflowAgent behavior: tool execution lifecycle events are dispatched where registered integrations are unavailable, so expected tool spans are missing.
Evidence
WorkflowAgentexports model-callchatspans but omitsexecute_toolspans for actual tool calls.- The globally registered telemetry integration's
onToolExecutionStartandonToolExecutionEndcallbacks are never invoked inside the workflow. - The same process correctly exports both model and tool spans when using plain
streamText, providing a concrete behavioral comparison and reproduction.
Identify bug discovery
Discovery source: discovery:audit (medium confidence).
The report appears to originate from inspecting the prior telemetry fix and the analogous tool-execution path in AI SDK source. It includes runtime validation, but does not establish actual production use.
- The author identifies specific source locations and calls in
workflow-agent.ts, includingexecuteToolWithCallbacksand the telemetry dispatcher lifecycle methods. - The report explicitly compares tool handling with the fix in #22378 and states that tool calls were not covered by that change.
- The author explains the source-level cause: workflow bodies cannot see
AI_SDK_TELEMETRY_INTEGRATIONS, making the dispatcher a no-op. - The behavior was checked against
main, consistent with source review and validation. - No statement establishes that the bug was discovered in a production application; the durable run and harness could be a reproduction or test.
Related: #23618 — the run itself has no root span either, from the same cause (the run's start and end are dispatched from the workflow body).
Thanks @robertyates for the precise report. The realm diagnosis is right, but I found two more things that keep tool spans missing even after moving the dispatch into a step:
executeToolWithCallbackssends tool events in the WorkflowAgent callback shape (durationMs,success, nocallId), not theToolExecution*Eventcontract.OpenTelemetrylooks up call state bycallIdand returns early, so tool spans are missing even with explicittelemetry.integrations.- Since #22480 each model call is its own operation and is closed before tools run, so there's no live parent for a tool span.
I opened #24334 with failing tests for each, plus a fix that reports each tool call as its own short operation from a step after the tool returns, the same pattern #22480 uses for model calls. 'use step' tools stay untouched.
@aayush-kapoor this shares a root cause with #23618 (run-level root span), which is assigned to you. I kept it to tool events only and shaped it so a future root span can parent these. Happy to adjust it, or to have you fold it into the #23618 work if that's simpler.
Resolved by #24408, released in @ai-sdk/[email protected]. With the durable bridge (OpenTelemetryIdGenerator + new OpenTelemetry({ durable })), a durable WorkflowAgent run now exports an execute_tool span for each tool call, with the original start and end times, under its step in the run's invoke_agent tree. We've confirmed this in our traces and removed our workaround. Closing.