Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,73 +197,6 @@ describe('Vercel AI integration', () => {
]),
};

// Todo: Add missing attribute spans for v5
// Right now only second span is recorded as it's manually opted in via explicit telemetry option
const EXPECTED_TRANSACTION_DEFAULT_PII_FALSE_V5 = {
transaction: 'main',
spans: expect.arrayContaining([
expect.objectContaining({
data: {
'vercel.ai.model.id': 'mock-model-id',
'vercel.ai.model.provider': 'mock-provider',
'vercel.ai.operationId': 'ai.generateText',
'vercel.ai.pipeline.name': 'generateText',
'vercel.ai.prompt': '{"prompt":"Where is the second span?"}',
'vercel.ai.response.finishReason': 'stop',
'gen_ai.response.text': expect.any(String),
'vercel.ai.settings.maxRetries': 2,
// 'vercel.ai.settings.maxSteps': 1,
'vercel.ai.streaming': false,
'gen_ai.prompt': '{"prompt":"Where is the second span?"}',
'gen_ai.response.model': 'mock-model-id',
'gen_ai.usage.input_tokens': 10,
'gen_ai.usage.output_tokens': 20,
'gen_ai.usage.total_tokens': 30,
'operation.name': 'ai.generateText',
'sentry.op': 'gen_ai.invoke_agent',
'sentry.origin': 'auto.vercelai.otel',
},
description: 'generateText',
op: 'gen_ai.invoke_agent',
origin: 'auto.vercelai.otel',
status: 'ok',
}),
// doGenerate
expect.objectContaining({
data: {
'sentry.origin': 'auto.vercelai.otel',
'sentry.op': 'gen_ai.generate_text',
'operation.name': 'ai.generateText.doGenerate',
'vercel.ai.operationId': 'ai.generateText.doGenerate',
'vercel.ai.model.provider': 'mock-provider',
'vercel.ai.model.id': 'mock-model-id',
'vercel.ai.settings.maxRetries': 2,
'gen_ai.system': 'mock-provider',
'gen_ai.request.model': 'mock-model-id',
'vercel.ai.pipeline.name': 'generateText.doGenerate',
'vercel.ai.streaming': false,
'vercel.ai.response.finishReason': 'stop',
'vercel.ai.response.model': 'mock-model-id',
'vercel.ai.response.id': expect.any(String),
'gen_ai.response.text': 'Second span here!',
'vercel.ai.response.timestamp': expect.any(String),
// 'vercel.ai.prompt.format': expect.any(String),
'gen_ai.request.messages': expect.any(String),
'gen_ai.response.finish_reasons': ['stop'],
'gen_ai.usage.input_tokens': 10,
'gen_ai.usage.output_tokens': 20,
'gen_ai.response.id': expect.any(String),
'gen_ai.response.model': 'mock-model-id',
'gen_ai.usage.total_tokens': 30,
},
description: 'generate_text mock-model-id',
op: 'gen_ai.generate_text',
origin: 'auto.vercelai.otel',
status: 'ok',
}),
]),
};

const EXPECTED_TRANSACTION_DEFAULT_PII_TRUE = {
transaction: 'main',
spans: expect.arrayContaining([
Expand Down Expand Up @@ -605,23 +538,6 @@ describe('Vercel AI integration', () => {
});
});

// Test with specific Vercel AI v5 version
createEsmAndCjsTests(
__dirname,
'scenario-v5.mjs',
'instrument.mjs',
(createRunner, test) => {
test('creates ai related spans with v5', async () => {
await createRunner().expect({ transaction: EXPECTED_TRANSACTION_DEFAULT_PII_FALSE_V5 }).start().completed();
});
},
{
additionalDependencies: {
ai: '^5.0.0',
},
},
);

createEsmAndCjsTests(__dirname, 'scenario-error-in-tool-express.mjs', 'instrument.mjs', (createRunner, test) => {
test('captures error in tool in express server', async () => {
const expectedTransaction = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/node';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
dsn: 'https://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
sendDefaultPii: true,
transport: loggingTransport,
integrations: [Sentry.vercelAIIntegration()],
});
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://[email protected]/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [Sentry.vercelAIIntegration()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as Sentry from '@sentry/node';
import { generateText, tool } from 'ai';
import { MockLanguageModelV2 } from 'ai/test';
import { z } from 'zod';

async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
await generateText({
model: new MockLanguageModelV2({
doGenerate: async () => ({
finishReason: 'tool-calls',
usage: { inputTokens: 15, outputTokens: 25, totalTokens: 40 },
content: [
{
type: 'tool-call',
toolCallId: 'call-1',
toolName: 'getWeather',
input: JSON.stringify({ location: 'San Francisco' }),
},
],
}),
}),
tools: {
getWeather: tool({
inputSchema: z.object({ location: z.string() }),
execute: async () => {
throw new Error('Error in tool');
},
}),
},
prompt: 'What is the weather in San Francisco?',
});
});
}

run();
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Sentry from '@sentry/node';
import { generateText } from 'ai';
import { generateText, tool } from 'ai';
import { MockLanguageModelV2 } from 'ai/test';
import { z } from 'zod';

Expand Down Expand Up @@ -35,24 +35,21 @@ async function run() {
doGenerate: async () => ({
finishReason: 'tool-calls',
usage: { inputTokens: 15, outputTokens: 25, totalTokens: 40 },
content: [{ type: 'text', text: 'Tool call completed!' }],
toolCalls: [
content: [
{
toolCallType: 'function',
type: 'tool-call',
toolCallId: 'call-1',
toolName: 'getWeather',
args: '{ "location": "San Francisco" }',
input: JSON.stringify({ location: 'San Francisco' }),
},
],
}),
}),
tools: {
getWeather: {
parameters: z.object({ location: z.string() }),
execute: async args => {
return `Weather in ${args.location}: Sunny, 72°F`;
},
},
getWeather: tool({
inputSchema: z.object({ location: z.string() }),
execute: async ({ location }) => `Weather in ${location}: Sunny, 72°F`,
}),
},
prompt: 'What is the weather in San Francisco?',
});
Expand Down
Loading
Loading