Uh oh!
There was an error while loading. Please reload this page.
feat(core): Migrate Vercel AI event processor to span streaming - #20608
Conversation
…sor migration Closes#20377 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
size-limit report 📦
|
… description side-channel Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ions The error scenario needs a try/catch so the process stays alive for flush. The invoke_agent span doesn't have token attributes when the tool errors, so remove those from the error test expectations. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… test In Vercel AI v6, the invoke_agent span does not get error status when a tool errors (matching the non-streaming v6 test behavior). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 44cc789. Configure here.
Uh oh!
There was an error while loading. Please reload this page.
chargome
left a comment
There was a problem hiding this comment.
Thanks for updating! LGTM now, I just hope we didn't overlook any edge cases where the map might leak 📿

Migrates the Vercel AI event processor so it also works in the span streaming path via the
processSpanhook. The event processor currently serves three purposes:Attribute renaming. The Vercel AI SDK emits attributes under
ai.*names that need to be renamed to OpenTelemetry semantic conventions (gen_ai.*) and thevercel.ai.*namespace. This logic is straightforward to port. It's extracted into a sharedprocessVercelAiSpanAttributeshelper that is now called from both the legacy event processor path (for transactions) and the newprocessSpanhook (for streamed spans).Token accumulation on parent spans. The event processor aggregates token usage from child spans onto their parent
invoke_agentspans. This is a cross-span operation that fundamentally doesn't work in the streaming model where spans are processed individually. The span streaming implementation guide explicitly lists this as a case that cannot be replaced. Since the plan is for parent-level token accumulation to go away regardless, we simply drop it for the streaming path.Tool descriptions on execute_tool spans. The event processor iterates over all spans in a transaction to find
gen_ai.request.available_toolsondoGeneratespans and applies the matching description to siblingexecute_toolspans. This cross-span iteration doesn't work when spans are processed individually. Instead, we parse and store tool descriptions in a map atspanStarttime of thedoGeneratespan. Sinceexecute_toolspans are siblings ofdoGenerate(both children ofinvoke_agent), we key the map by the parent span ID soexecute_toolspans can look up descriptions by their ownparent_span_id. This assumes a flat sibling hierarchy, which holds for our test scenarios. If we encounter more complex cases down the road, I think it's fine to address in a follow-up.Closes#20377