feat(server-utils): Add orchestrion support for Vercel AI v4#22139
Open
mydea wants to merge 5 commits into
Open
feat(server-utils): Add orchestrion support for Vercel AI v4#22139mydea wants to merge 5 commits into
mydea wants to merge 5 commits into
Conversation
Contributor
size-limit report 📦
|
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>
cd82432 to
e794095
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends the orchestrion diagnostics-channel instrumentation to cover the
aiSDK 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 OTelSentryVercelAiInstrumentationcan eventually be retired.v4 differs from v5/v6 in three ways, all handled by reusing the existing shared span-building core:
resolveLanguageModelchokepoint — v4 calls the passedLanguageModelV1(specificationVersion: 'v1') directly, so itsdoGenerate/doStreamare patched at the operation start instead, gated on'v1'so v5/v6 models are never touched (strictly additive). Tool calls reuse the existing per-toolexecutepatch, and the model-call tool list is read from v4'smode.tools.promptTokens/completionTokens(v4) alongsideinputTokens/outputTokens(v5+); the fallbacks areundefined-inert on v5+.accumulateChunkreadstextDelta(v4) alongsidedelta(v5+).The top-level
systemprompt is also lifted intoinstructionsfor v4/v5/v6, matching v7's native channel.The v4 integration-test suites (
vercelaiandspan-streaming-v4) now run under orchestrion as well as the OTel processor, and a newstreamTextscenario covers the v4doStreampath.Fixes #20914
🤖 Generated with Claude Code