Repository navigation
fix(server-utils): Trace Vercel AI streamObject on ai v4-v6 #26382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andreiborza
merged 4 commits into
getsentry:develop
from
mvanhorn:fix/25779-vercel-ai-streamobject-spans
Nov 16, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
aa7a1d1
fix(scenario-stream-object): trace Vercel AI streamObject on ai v4-v6
mvanhorn 9f8c879
test(vercel-ai): Use span op constants in streamObject tests
mvanhorn 2c66de0
fix(vercel-ai): Keep streamObject usage when object validation fails
mvanhorn 1cdb122
Use a local streamed instrument file for the v4 streamObject test
andreiborza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...packages/node-integration-tests/suites/tracing/vercelai/v4-static/instrument-streamed.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| dataCollection: { genAI: { inputs: false, outputs: false } }, | ||
| transport: loggingTransport, | ||
| }); |
42 changes: 42 additions & 0 deletions
42
...kages/node-integration-tests/suites/tracing/vercelai/v4-static/scenario-stream-object.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { streamObject } from 'ai'; | ||
| import { convertArrayToReadableStream, MockLanguageModelV1 } from 'ai/test'; | ||
| import { z } from 'zod'; | ||
|
|
||
| async function run() { | ||
| await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { | ||
| const result = streamObject({ | ||
| experimental_telemetry: { isEnabled: true, recordInputs: true, recordOutputs: true }, | ||
| model: new MockLanguageModelV1({ | ||
| defaultObjectGenerationMode: 'json', | ||
| doStream: async () => ({ | ||
| stream: convertArrayToReadableStream([ | ||
| { type: 'response-metadata', id: 'resp-1', modelId: 'mock-model-id' }, | ||
| { type: 'text-delta', textDelta: '{ "name": "John Doe",' }, | ||
| { type: 'text-delta', textDelta: ' "age": 30 }' }, | ||
| { | ||
| type: 'finish', | ||
| finishReason: 'stop', | ||
| usage: { promptTokens: 15, completionTokens: 25 }, | ||
| }, | ||
| ]), | ||
| rawCall: { rawPrompt: null, rawSettings: {} }, | ||
| }), | ||
| }), | ||
| schema: z.object({ | ||
| name: z.string(), | ||
| age: z.number(), | ||
| }), | ||
| prompt: 'Generate a person object', | ||
| }); | ||
|
|
||
| // streamObject returns synchronously; drive the lazy stream to completion so the spans finish. | ||
| for await (const _part of result.partialObjectStream) { | ||
| void _part; | ||
| } | ||
| }); | ||
|
|
||
| await Sentry.flush(2000); | ||
| } | ||
|
|
||
| run(); |
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
53 changes: 53 additions & 0 deletions
53
...s/node-integration-tests/suites/tracing/vercelai/v6_v7/scenario-stream-object-invalid.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { streamObject } from 'ai'; | ||
| import { MockLanguageModelV3, simulateReadableStream } from 'ai/test'; | ||
| import { z } from 'zod'; | ||
|
|
||
| async function run() { | ||
| await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { | ||
| const result = streamObject({ | ||
| experimental_telemetry: { isEnabled: true, recordInputs: true, recordOutputs: true }, | ||
| model: new MockLanguageModelV3({ | ||
| doStream: async () => ({ | ||
| stream: simulateReadableStream({ | ||
| chunks: [ | ||
| { type: 'stream-start', warnings: [] }, | ||
| { type: 'text-start', id: '0' }, | ||
| { type: 'text-delta', id: '0', delta: '{ "name": "John Doe",' }, | ||
| { type: 'text-delta', id: '0', delta: ' "age": "thirty" }' }, | ||
| { type: 'text-end', id: '0' }, | ||
| { | ||
| type: 'finish', | ||
| finishReason: { unified: 'stop', raw: 'stop' }, | ||
| usage: { | ||
| inputTokens: { total: 15, noCache: 15, cached: 0 }, | ||
| outputTokens: { total: 25, noCache: 25, cached: 0 }, | ||
| totalTokens: { total: 40, noCache: 40, cached: 0 }, | ||
| }, | ||
| }, | ||
| ], | ||
| }), | ||
| }), | ||
| }), | ||
| schema: z.object({ | ||
| name: z.string(), | ||
| age: z.number(), | ||
| }), | ||
| prompt: 'Generate a person object', | ||
| }); | ||
|
|
||
| // streamObject returns synchronously; drive the lazy stream to completion so | ||
| // the spans actually finish. | ||
| for await (const _part of result.partialObjectStream) { | ||
| void _part; | ||
| } | ||
|
|
||
| try { | ||
| await result.object; | ||
| } catch { | ||
| // Expected: `age` fails schema validation after the model call succeeded. | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| run(); |
47 changes: 47 additions & 0 deletions
47
dev-packages/node-integration-tests/suites/tracing/vercelai/v6_v7/scenario-stream-object.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { streamObject } from 'ai'; | ||
| import { MockLanguageModelV3, simulateReadableStream } from 'ai/test'; | ||
| import { z } from 'zod'; | ||
|
|
||
| async function run() { | ||
| await Sentry.startSpan({ op: 'function', name: 'main' }, async () => { | ||
| const result = streamObject({ | ||
| experimental_telemetry: { isEnabled: true, recordInputs: true, recordOutputs: true }, | ||
| model: new MockLanguageModelV3({ | ||
| doStream: async () => ({ | ||
| stream: simulateReadableStream({ | ||
| chunks: [ | ||
| { type: 'stream-start', warnings: [] }, | ||
| { type: 'text-start', id: '0' }, | ||
| { type: 'text-delta', id: '0', delta: '{ "name": "John Doe",' }, | ||
| { type: 'text-delta', id: '0', delta: ' "age": 30 }' }, | ||
| { type: 'text-end', id: '0' }, | ||
| { | ||
| type: 'finish', | ||
| finishReason: { unified: 'stop', raw: 'stop' }, | ||
| usage: { | ||
| inputTokens: { total: 15, noCache: 15, cached: 0 }, | ||
| outputTokens: { total: 25, noCache: 25, cached: 0 }, | ||
| totalTokens: { total: 40, noCache: 40, cached: 0 }, | ||
| }, | ||
| }, | ||
| ], | ||
| }), | ||
| }), | ||
| }), | ||
| schema: z.object({ | ||
| name: z.string(), | ||
| age: z.number(), | ||
| }), | ||
| prompt: 'Generate a person object', | ||
| }); | ||
|
|
||
| // streamObject returns synchronously; drive the lazy stream to completion so | ||
| // the spans actually finish. | ||
| for await (const _part of result.partialObjectStream) { | ||
| void _part; | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| run(); |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.