Skip to content

feat(core): Migrate Vercel AI event processor to span streaming - #20608

Merged
nicohrubec merged 12 commits into
developfrom
nh/span-streaming-vercelai-migration
May 6, 2026
Merged

feat(core): Migrate Vercel AI event processor to span streaming#20608
nicohrubec merged 12 commits into
developfrom
nh/span-streaming-vercelai-migration

Conversation

@nicohrubec

@nicohrubecnicohrubec commented Apr 30, 2026

Copy link
Copy Markdown
Member

Migrates the Vercel AI event processor so it also works in the span streaming path via the processSpan hook. 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 the vercel.ai.* namespace. This logic is straightforward to port. It's extracted into a shared processVercelAiSpanAttributes helper that is now called from both the legacy event processor path (for transactions) and the new processSpan hook (for streamed spans).

Token accumulation on parent spans. The event processor aggregates token usage from child spans onto their parent invoke_agent spans. 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_tools on doGenerate spans and applies the matching description to sibling execute_tool spans. This cross-span iteration doesn't work when spans are processed individually. Instead, we parse and store tool descriptions in a map at spanStart time of the doGenerate span. Since execute_tool spans are siblings of doGenerate (both children of invoke_agent), we key the map by the parent span ID so execute_tool spans can look up descriptions by their own parent_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

…sor migration
Closes#20377
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions

github-actionsBot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser26.3 kB--
@sentry/browser - with treeshaking flags24.78 kB--
@sentry/browser (incl. Tracing)44.17 kB--
@sentry/browser (incl. Tracing + Span Streaming)46.39 kB--
@sentry/browser (incl. Tracing, Profiling)49.14 kB--
@sentry/browser (incl. Tracing, Replay)83.55 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags73.01 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)88.23 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)100.84 kB--
@sentry/browser (incl. Feedback)43.44 kB--
@sentry/browser (incl. sendFeedback)31.11 kB--
@sentry/browser (incl. FeedbackAsync)36.19 kB--
@sentry/browser (incl. Metrics)27.6 kB--
@sentry/browser (incl. Logs)27.73 kB--
@sentry/browser (incl. Metrics & Logs)28.43 kB--
@sentry/react28.04 kB--
@sentry/react (incl. Tracing)46.4 kB--
@sentry/vue31.18 kB--
@sentry/vue (incl. Tracing)46.02 kB--
@sentry/svelte26.32 kB--
CDN Bundle28.91 kB--
CDN Bundle (incl. Tracing)46.94 kB--
CDN Bundle (incl. Logs, Metrics)30.34 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)48.04 kB--
CDN Bundle (incl. Replay, Logs, Metrics)69.4 kB--
CDN Bundle (incl. Tracing, Replay)84.07 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)85.15 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)89.89 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)90.97 kB--
CDN Bundle - uncompressed84.88 kB--
CDN Bundle (incl. Tracing) - uncompressed140.44 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed89.08 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed143.9 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed212.99 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed258.24 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed261.69 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed271.94 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed275.38 kB--
@sentry/nextjs (client)48.9 kB--
@sentry/sveltekit (client)44.64 kB--
@sentry/node-core59.81 kB+0.02%+10 B 🔺
@sentry/node163.56 kB+0.09%+144 B 🔺
@sentry/node - without tracing72.28 kB+0.02%+9 B 🔺
@sentry/aws-serverless106.95 kB+0.01%+7 B 🔺
@sentry/cloudflare (withSentry) - minified168.38 kB--
@sentry/cloudflare (withSentry)424.9 kB--

View base workflow run

@nicohrubecnicohrubec changed the title test(vercelai): Add span streaming integration tests for event processor migrationfeat(vercelai): Migrate Vercel AI event processor to span streamingMay 5, 2026
nicohrubecand others added 5 commits May 5, 2026 19:40
… 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>
@nicohrubec
nicohrubec marked this pull request as ready for review May 6, 2026 08:31
@nicohrubec
nicohrubec requested a review from a team as a code ownerMay 6, 2026 08:31
@nicohrubec
nicohrubec requested a review from chargomeMay 6, 2026 08:32
Comment threadpackages/core/src/tracing/vercel-ai/index.ts
@nicohrubecnicohrubec changed the title feat(vercelai): Migrate Vercel AI event processor to span streamingfeat(core): Migrate Vercel AI event processor to span streamingMay 6, 2026
Comment threadpackages/core/src/tracing/vercel-ai/index.ts
Comment threadpackages/core/src/index.ts Outdated
@nicohrubec
nicohrubec requested a review from chargomeMay 6, 2026 10:58

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

@chargomechargome left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating! LGTM now, I just hope we didn't overlook any edge cases where the map might leak 📿

@nicohrubec
nicohrubec merged commit 01d0a70 into developMay 6, 2026
512 of 513 checks passed
@nicohrubec
nicohrubec deleted the nh/span-streaming-vercelai-migration branch May 6, 2026 12:29
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event processor migration: Vercel AI event processor

2 participants

@nicohrubec@chargome