-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(node): Add v7 support for vercelAiIntegration
#21613
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
Draft
mydea
wants to merge
5
commits into
develop
Choose a base branch
from
fn/vercel-ai-v7
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
421 changes: 0 additions & 421 deletions
421
dev-packages/node-integration-tests/suites/tracing/vercelai/v6/test.ts
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
430 changes: 430 additions & 0 deletions
430
dev-packages/node-integration-tests/suites/tracing/vercelai/v6_v7/test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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
143 changes: 143 additions & 0 deletions
143
packages/node/test/integrations/tracing/vercelai/channel.test.ts
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,143 @@ | ||
| import { tracingChannel } from 'node:diagnostics_channel'; | ||
| import type { SpanJSON, TransactionEvent } from '@sentry/core'; | ||
| import { tracingChannel as otelTracingChannel } from '@sentry/opentelemetry/tracing-channel'; | ||
| import { subscribeVercelAiTracingChannel } from '@sentry/server-utils'; | ||
| import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'; | ||
| import * as Sentry from '../../../../src'; | ||
| import { cleanupOtel, mockSdkInit } from '../../../helpers/mockSdkInit'; | ||
|
|
||
| const channel = tracingChannel<Record<string, unknown>, Record<string, unknown>>('ai:telemetry'); | ||
|
|
||
| const transactions: TransactionEvent[] = []; | ||
|
|
||
| describe('Vercel AI telemetry tracing channel', () => { | ||
| beforeAll(() => { | ||
| mockSdkInit({ | ||
| tracesSampleRate: 1, | ||
| dataCollection: { genAI: { inputs: true, outputs: true } }, | ||
| beforeSendTransaction: event => { | ||
| transactions.push(event); | ||
| return null; | ||
| }, | ||
| }); | ||
| // The OTel context manager is registered by `mockSdkInit` above, so we can subscribe directly. | ||
| subscribeVercelAiTracingChannel(otelTracingChannel); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| cleanupOtel(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| transactions.length = 0; | ||
| }); | ||
|
|
||
| it('builds a parented, fully-formed gen_ai span tree from the ai:telemetry channel', async () => { | ||
| await channel.tracePromise( | ||
| async () => { | ||
| await channel.tracePromise( | ||
| async () => ({ | ||
| usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 }, | ||
| finishReason: 'stop', | ||
| text: 'Hi there', | ||
| response: { id: 'resp-1', modelId: 'gpt-4o-2024' }, | ||
| }), | ||
| { type: 'languageModelCall', event: { callId: 'call-1', provider: 'openai', modelId: 'gpt-4o' } }, | ||
| ); | ||
|
|
||
| await channel.tracePromise(async () => ({ output: { temperature: 70 } }), { | ||
| type: 'executeTool', | ||
| event: { | ||
| callId: 'call-1', | ||
| toolCallId: 'tool-1', | ||
| toolCall: { toolName: 'getWeather', toolCallId: 'tool-1', input: { city: 'SF' } }, | ||
| }, | ||
| }); | ||
|
|
||
| return { usage: { inputTokens: 10, outputTokens: 20, totalTokens: 30 }, finishReason: 'stop' }; | ||
| }, | ||
| { | ||
| type: 'generateText', | ||
| event: { | ||
| callId: 'call-1', | ||
| provider: 'openai', | ||
| modelId: 'gpt-4o', | ||
| functionId: 'my-agent', | ||
| messages: [{ role: 'user', content: 'Hello' }], | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| await Sentry.getClient()!.flush(); | ||
|
|
||
| expect(transactions).toHaveLength(1); | ||
| const transaction = transactions[0]!; | ||
|
|
||
| expect(transaction.transaction).toBe('invoke_agent my-agent'); | ||
| expect(transaction.contexts?.trace).toEqual( | ||
| expect.objectContaining({ | ||
| op: 'gen_ai.invoke_agent', | ||
| origin: 'auto.vercelai.channel', | ||
| data: expect.objectContaining({ | ||
| 'gen_ai.operation.name': 'invoke_agent', | ||
| 'gen_ai.system': 'openai', | ||
| 'gen_ai.request.model': 'gpt-4o', | ||
| 'gen_ai.response.streaming': false, | ||
| 'gen_ai.function_id': 'my-agent', | ||
| 'gen_ai.input.messages': JSON.stringify([{ role: 'user', content: 'Hello' }]), | ||
| }), | ||
| }), | ||
| ); | ||
|
|
||
| const rootSpanId = transaction.contexts?.trace?.span_id; | ||
| const spans = transaction.spans ?? []; | ||
| const modelCallSpan = spans.find((span: SpanJSON) => span.op === 'gen_ai.generate_content'); | ||
| const toolSpan = spans.find((span: SpanJSON) => span.op === 'gen_ai.execute_tool'); | ||
|
|
||
| // Model call and tool call are siblings parented under the invoke_agent span. | ||
| expect(modelCallSpan?.parent_span_id).toBe(rootSpanId); | ||
| expect(toolSpan?.parent_span_id).toBe(rootSpanId); | ||
|
|
||
| expect(modelCallSpan?.description).toBe('generate_content gpt-4o'); | ||
| expect(modelCallSpan?.data).toEqual( | ||
| expect.objectContaining({ | ||
| 'gen_ai.operation.name': 'generate_content', | ||
| 'gen_ai.request.model': 'gpt-4o', | ||
| 'gen_ai.usage.input_tokens': 10, | ||
| 'gen_ai.usage.output_tokens': 20, | ||
| 'gen_ai.usage.total_tokens': 30, | ||
| 'gen_ai.response.finish_reasons': JSON.stringify(['stop']), | ||
| 'gen_ai.response.id': 'resp-1', | ||
| 'gen_ai.response.model': 'gpt-4o-2024', | ||
| 'gen_ai.output.messages': | ||
| '[{"role":"assistant","parts":[{"type":"text","content":"Hi there"}],"finish_reason":"stop"}]', | ||
| }), | ||
| ); | ||
|
|
||
| expect(toolSpan?.description).toBe('execute_tool getWeather'); | ||
| expect(toolSpan?.data).toEqual( | ||
| expect.objectContaining({ | ||
| 'gen_ai.operation.name': 'execute_tool', | ||
| 'gen_ai.tool.type': 'function', | ||
| 'gen_ai.tool.name': 'getWeather', | ||
| 'gen_ai.tool.call.id': 'tool-1', | ||
| 'gen_ai.tool.input': JSON.stringify({ city: 'SF' }), | ||
| 'gen_ai.tool.output': JSON.stringify({ temperature: 70 }), | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| it('marks the span as errored when the traced operation rejects', async () => { | ||
| await expect( | ||
| channel.tracePromise(async () => Promise.reject(new Error('boom')), { | ||
| type: 'generateText', | ||
| event: { callId: 'call-err', provider: 'openai', modelId: 'gpt-4o' }, | ||
| }), | ||
| ).rejects.toThrow('boom'); | ||
|
|
||
| await Sentry.getClient()!.flush(); | ||
|
|
||
| expect(transactions).toHaveLength(1); | ||
| expect(transactions[0]!.contexts?.trace?.status).toBe('internal_error'); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
V7 never registers Vercel processors
High Severity
With
aiv7, OTel instrumentation no longer patches the package, socallWhenPatchednever runs.addVercelAiProcessorsis only registered whenshouldForceis true atafterAllSetup. If the Modules integration does not listaithen (typical for ESM before import or whenaiis missing from cwdpackage.jsondependencies), v7 channel spans are emitted but transaction processors never run—no tool descriptions, parent token rollup, or related enrichment.Reviewed by Cursor Bugbot for commit 21822ce. Configure here.