Skip to content

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

Open
mydea wants to merge 5 commits into
developfrom
feat/vercel-ai-v4-orchestrion
Open

feat(server-utils): Add orchestrion support for Vercel AI v4#22139
mydea wants to merge 5 commits into
developfrom
feat/vercel-ai-v4-orchestrion

Conversation

@mydea

@mydea mydea 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-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.59 kB - -
@sentry/browser - with treeshaking flags 26.03 kB - -
@sentry/browser (incl. Tracing) 46.34 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.13 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.12 kB - -
@sentry/browser (incl. Tracing, Replay) 85.62 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.26 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.32 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 102.97 kB - -
@sentry/browser (incl. Feedback) 44.76 kB - -
@sentry/browser (incl. sendFeedback) 32.38 kB - -
@sentry/browser (incl. FeedbackAsync) 37.51 kB - -
@sentry/browser (incl. Metrics) 28.67 kB - -
@sentry/browser (incl. Logs) 28.91 kB - -
@sentry/browser (incl. Metrics & Logs) 29.59 kB - -
@sentry/react 29.38 kB - -
@sentry/react (incl. Tracing) 48.61 kB - -
@sentry/vue 33.03 kB - -
@sentry/vue (incl. Tracing) 48.3 kB - -
@sentry/svelte 27.61 kB - -
CDN Bundle 30 kB - -
CDN Bundle (incl. Tracing) 48.32 kB - -
CDN Bundle (incl. Logs, Metrics) 31.57 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.64 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.81 kB - -
CDN Bundle (incl. Tracing, Replay) 85.84 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.14 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.92 kB - -
CDN Bundle - uncompressed 89.35 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.1 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.05 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.07 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 218.78 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.3 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.26 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 282.95 kB - -
@sentry/nextjs (client) 51.16 kB - -
@sentry/sveltekit (client) 46.78 kB - -
@sentry/core/server 78.42 kB - -
@sentry/core/browser 64.74 kB - -
@sentry/node-core 62.72 kB - -
@sentry/node 125.4 kB +0.02% +25 B 🔺
@sentry/node (incl. diagnostics channel injection) 138.65 kB +0.08% +105 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 69.95 kB - -
@sentry/node/light 50.72 kB - -
@sentry/node - without tracing 74.06 kB +0.01% +1 B 🔺
@sentry/aws-serverless 85.5 kB - -
@sentry/cloudflare (withSentry) - minified 181.71 kB - -
@sentry/cloudflare (withSentry) 449.16 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 owner July 9, 2026 12:39
@mydea mydea requested review from JPeer264 and andreiborza and removed request for a team July 9, 2026 12:39
mydea and others added 5 commits July 9, 2026 14:57
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 mydea force-pushed the feat/vercel-ai-v4-orchestrion branch from cd82432 to e794095 Compare July 9, 2026 12:57
Sign up for free to 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

1 participant