Skip to content

feat(server-utils): Add orchestrion support for Vercel AI v4 - #22139

Merged
mydea merged 6 commits into
developfrom
feat/vercel-ai-v4-orchestrion
Jul 10, 2026
Merged

feat(server-utils): Add orchestrion support for Vercel AI v4#22139
mydea merged 6 commits into
developfrom
feat/vercel-ai-v4-orchestrion

Conversation

@mydea

@mydeamydea commented Jul 9, 2026

Copy link
Copy Markdown
Member

Extends the orchestrion diagnostics-channel instrumentation to cover the ai SDK v4 (>=4.0.0 <5.0.0), so the channel path now covers v4/v5/v6/v7 and emits spans identical to the OTel processor. This closes the last version gap before the OTel SentryVercelAiInstrumentation can eventually be retired.

v4 differs from v5/v6 in three ways, all handled by reusing the existing shared span-building core:

  • No resolveLanguageModel chokepoint — v4 calls the passed LanguageModelV1 (specificationVersion: 'v1') directly, so its doGenerate/doStream are patched at the operation start instead, gated on 'v1' so v5/v6 models are never touched (strictly additive). Tool calls reuse the existing per-tool execute patch, and the model-call tool list is read from v4's mode.tools.
  • Token names — the shared core now reads promptTokens/completionTokens (v4) alongside inputTokens/outputTokens (v5+); the fallbacks are undefined-inert on v5+.
  • Streamed text deltaaccumulateChunk reads textDelta (v4) alongside delta (v5+).

The top-level system prompt is also lifted into instructions for v4/v5/v6, matching v7's native channel.

The v4 integration-test suites (vercelai and span-streaming-v4) now run under orchestrion as well as the OTel processor, and a new streamText scenario covers the v4 doStream path.

Fixes#20914

🤖 Generated with Claude Code

@github-actions

github-actionsBot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser27.6 kB--
@sentry/browser - with treeshaking flags26.04 kB--
@sentry/browser (incl. Tracing)46.35 kB--
@sentry/browser (incl. Tracing + Span Streaming)48.14 kB--
@sentry/browser (incl. Tracing, Profiling)51.13 kB--
@sentry/browser (incl. Tracing, Replay)85.62 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags75.25 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)90.33 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)102.99 kB--
@sentry/browser (incl. Feedback)44.78 kB--
@sentry/browser (incl. sendFeedback)32.4 kB--
@sentry/browser (incl. FeedbackAsync)37.53 kB--
@sentry/browser (incl. Metrics)28.68 kB--
@sentry/browser (incl. Logs)28.93 kB--
@sentry/browser (incl. Metrics & Logs)29.61 kB--
@sentry/react29.39 kB--
@sentry/react (incl. Tracing)48.62 kB--
@sentry/vue33.03 kB--
@sentry/vue (incl. Tracing)48.33 kB--
@sentry/svelte27.63 kB--
CDN Bundle30 kB--
CDN Bundle (incl. Tracing)48.33 kB--
CDN Bundle (incl. Logs, Metrics)31.58 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)49.65 kB--
CDN Bundle (incl. Replay, Logs, Metrics)70.81 kB--
CDN Bundle (incl. Tracing, Replay)85.83 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)87.15 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)91.64 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)92.91 kB--
CDN Bundle - uncompressed89.33 kB--
CDN Bundle (incl. Tracing) - uncompressed146.07 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed94.03 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed150.05 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed218.71 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed265.23 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed269.18 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed278.93 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed282.88 kB--
@sentry/nextjs (client)51.17 kB--
@sentry/sveltekit (client)46.8 kB--
@sentry/core/server78.42 kB--
@sentry/core/browser64.77 kB--
@sentry/node-core62.72 kB-0.01%-1 B 🔽
@sentry/node125.35 kB+0.02%+24 B 🔺
@sentry/node (incl. diagnostics channel injection)138.61 kB+0.08%+104 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection)69.95 kB--
@sentry/node/light50.73 kB-0.01%-1 B 🔽
@sentry/node - without tracing74.04 kB+0.01%+1 B 🔺
@sentry/aws-serverless83.26 kB+0.01%+2 B 🔺
@sentry/cloudflare (withSentry) - minified181.47 kB--
@sentry/cloudflare (withSentry)448.98 kB--

View base workflow run

@mydea
mydea marked this pull request as ready for review July 9, 2026 12:39
@mydea
mydea requested a review from a team as a code ownerJuly 9, 2026 12:39
@mydea
mydea requested review from JPeer264 and andreiborza and removed request for a teamJuly 9, 2026 12:39
@mydea
mydeaforce-pushed the feat/vercel-ai-v4-orchestrion branch from cd82432 to e794095CompareJuly 9, 2026 12:57

@andreiborzaandreiborza 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.

Nice

mydeaand others added 5 commits July 10, 2026 09:11
Extends the orchestrion diagnostics-channel instrumentation to cover the
`ai` SDK v4 (`>=4.0.0 <5.0.0`), so the channel path now covers v4/v5/v6/v7
and produces spans identical to the OTel processor.
v4 differs from v5/v6 in three load-bearing ways, all handled by reusing
the existing shared core:
- No `resolveLanguageModel` chokepoint: v4 calls the passed `LanguageModelV1`
(`specificationVersion: 'v1'`) directly, so its `doGenerate`/`doStream` are
patched at the operation start instead, gated on `'v1'` so v5/v6 models are
untouched. Tool calls reuse the existing per-tool `execute` patch, and the
model-call tool list is read from v4's `mode.tools`.
- Token names: the shared core now reads `promptTokens`/`completionTokens`
(v4) as well as `inputTokens`/`outputTokens` (v5+); the fallbacks are inert
on v5+.
- Streamed text delta: `accumulateChunk` reads `textDelta` (v4) as well as
`delta` (v5+).
The top-level `system` prompt is also lifted into `instructions` for all of
v4/v5/v6, matching v7's native channel.
The v4 integration-test suites now run under orchestrion as well as the OTel
processor, plus a new `streamText` scenario covering the v4 `doStream` path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
v6 emits generateObject spans via orchestrion; v7's native ai:telemetry
channel does not publish generateObject (like embedMany), so the v7 case
is skipped with a documenting comment.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mydea
mydeaforce-pushed the feat/vercel-ai-v4-orchestrion branch from e794095 to 7179dc1CompareJuly 10, 2026 07:11
@mydea
mydea enabled auto-merge (squash) July 10, 2026 07:11

@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 7179dc1. Configure here.

Comment threadpackages/server-utils/src/vercel-ai/vercel-ai-orchestrion-subscriber.ts Outdated
Comment threadpackages/server-utils/src/vercel-ai/vercel-ai-orchestrion-subscriber.ts Outdated
@mydea
mydea merged commit e934b44 into developJul 10, 2026
216 checks passed
@mydea
mydea deleted the feat/vercel-ai-v4-orchestrion branch July 10, 2026 07:44
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.

Rewrite SentryVercelAiInstrumentation to orchestrion

2 participants

@mydea@andreiborza