Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
@@ -0,0 +1,12 @@
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,
sendDefaultPii: true,
transport: loggingTransport,
integrations: [Sentry.vercelAIIntegration()],
streamGenAiSpans: true,
});
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://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
transport: loggingTransport,
integrations: [Sentry.vercelAIIntegration()],
streamGenAiSpans: true,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as Sentry from '@sentry/node';
import { generateText } from 'ai';
import { MockLanguageModelV3 } from 'ai/test';

async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
await generateText({
telemetry: { isEnabled: false },
model: new MockLanguageModelV3({
doGenerate: async () => ({
finishReason: { unified: 'stop', raw: 'stop' },
usage: {
inputTokens: { total: 10, noCache: 10, cached: 0 },
outputTokens: { total: 20, noCache: 20, cached: 0 },
totalTokens: { total: 30, noCache: 30, cached: 0 },
},
content: [{ type: 'text', text: 'Should not be captured' }],
warnings: [],
}),
}),
prompt: 'This should be silent',
});
});
}

run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as Sentry from '@sentry/node';
import { embed } from 'ai';
import { MockEmbeddingModelV3 } from 'ai/test';

async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
await embed({
model: new MockEmbeddingModelV3({
doEmbed: async () => ({
embeddings: [[0.1, 0.2, 0.3]],
usage: { tokens: 5 },
}),
}),
value: 'Hello world',
});
});
}

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

async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
await generateText({
model: new MockLanguageModelV3({
doGenerate: async () => ({
finishReason: { unified: 'tool-calls', raw: 'tool_calls' },
usage: {
inputTokens: { total: 15, noCache: 15, cached: 0 },
outputTokens: { total: 25, noCache: 25, cached: 0 },
totalTokens: { total: 40, noCache: 40, cached: 0 },
},
content: [
{
type: 'tool-call',
toolCallId: 'call-1',
toolName: 'getWeather',
input: JSON.stringify({ location: 'San Francisco' }),
},
],
warnings: [],
}),
}),
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
@@ -0,0 +1,31 @@
import * as Sentry from '@sentry/node';
import { streamText, tool } from 'ai';

Check warning on line 2 in dev-packages/node-integration-tests/suites/tracing/vercelai/v7/scenario-stream-text.mjs

View workflow job for this annotation

GitHub Actions / Lint

eslint(no-unused-vars)

Identifier 'tool' is imported but never used.
import { MockLanguageModelV3 } from 'ai/test';
import { z } from 'zod';

Check warning on line 4 in dev-packages/node-integration-tests/suites/tracing/vercelai/v7/scenario-stream-text.mjs

View workflow job for this annotation

GitHub Actions / Lint

eslint(no-unused-vars)

Identifier 'z' is imported but never used.

async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
const { textStream } = streamText({
model: new MockLanguageModelV3({
doGenerate: async () => ({
finishReason: { unified: 'stop', raw: 'stop' },
usage: {
inputTokens: { total: 10, noCache: 10, cached: 0 },
outputTokens: { total: 20, noCache: 20, cached: 0 },
totalTokens: { total: 30, noCache: 30, cached: 0 },
},
content: [{ type: 'text', text: 'Streamed response!' }],
warnings: [],
}),
}),
prompt: 'Stream me a response',
});

const chunks = [];
for await (const chunk of textStream) {
chunks.push(chunk);
}
});
}

run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as Sentry from '@sentry/node';
import { ToolLoopAgent, stepCountIs, tool } from 'ai';
import { MockLanguageModelV3 } from 'ai/test';
import { z } from 'zod';

async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
let callCount = 0;

const agent = new ToolLoopAgent({
telemetry: { functionId: 'weather_agent' },
model: new MockLanguageModelV3({
doGenerate: async () => {
if (callCount++ === 0) {
return {
finishReason: { unified: 'tool-calls', raw: 'tool_calls' },
usage: {
inputTokens: { total: 10, noCache: 10, cached: 0 },
outputTokens: { total: 20, noCache: 20, cached: 0 },
totalTokens: { total: 30, noCache: 30, cached: 0 },
},
content: [
{
type: 'tool-call',
toolCallId: 'call-1',
toolName: 'getWeather',
input: JSON.stringify({ location: 'San Francisco' }),
},
],
warnings: [],
};
}
return {
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 },
},
content: [{ type: 'text', text: 'The weather in San Francisco is sunny, 72°F.' }],
warnings: [],
};
},
}),
tools: {
getWeather: tool({
description: 'Get the current weather for a location',
inputSchema: z.object({ location: z.string() }),
execute: async ({ location }) => `Weather in ${location}: Sunny, 72°F`,
}),
},
stopWhen: stepCountIs(3),
});

await agent.generate({
prompt: 'What is the weather in San Francisco?',
});
});
}

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

async function run() {
await Sentry.startSpan({ op: 'function', name: 'main' }, async () => {
// Basic generateText — no telemetry config needed, DC subscriber auto-captures
await generateText({
model: new MockLanguageModelV3({
doGenerate: async () => ({
finishReason: { unified: 'stop', raw: 'stop' },
usage: {
inputTokens: { total: 10, noCache: 10, cached: 0 },
outputTokens: { total: 20, noCache: 20, cached: 0 },
totalTokens: { total: 30, noCache: 30, cached: 0 },
},
content: [{ type: 'text', text: 'First response!' }],
warnings: [],
}),
}),
prompt: 'Where is the first span?',
});

// generateText with tool calls
await generateText({
model: new MockLanguageModelV3({
doGenerate: async () => ({
finishReason: { unified: 'tool-calls', raw: 'tool_calls' },
usage: {
inputTokens: { total: 15, noCache: 15, cached: 0 },
outputTokens: { total: 25, noCache: 25, cached: 0 },
totalTokens: { total: 40, noCache: 40, cached: 0 },
},
content: [
{
type: 'tool-call',
toolCallId: 'call-1',
toolName: 'getWeather',
input: JSON.stringify({ location: 'San Francisco' }),
},
],
warnings: [],
}),
}),
tools: {
getWeather: tool({
description: 'Get the current weather for a location',
inputSchema: z.object({ location: z.string() }),
execute: async ({ location }) => `Weather in ${location}: Sunny, 72°F`,
}),
},
prompt: 'What is the weather in San Francisco?',
});

// generateText with telemetry explicitly disabled — should NOT produce spans
await generateText({
telemetry: { isEnabled: false },
model: new MockLanguageModelV3({
doGenerate: async () => ({
finishReason: { unified: 'stop', raw: 'stop' },
usage: {
inputTokens: { total: 10, noCache: 10, cached: 0 },
outputTokens: { total: 20, noCache: 20, cached: 0 },
totalTokens: { total: 30, noCache: 30, cached: 0 },
},
content: [{ type: 'text', text: 'Should not be captured!' }],
warnings: [],
}),
}),
prompt: 'This should be silent',
});
});
}

run();
Loading
Loading