Skip to content

Commit 4fba247

Browse files
committed
Revert "try timeout sol"
This reverts commit 1607304.
1 parent e41d2ad commit 4fba247

File tree

2 files changed

+171
-0
lines changed

2 files changed

+171
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import * as Sentry from '@sentry/node';
2+
import { generateText, tool } from 'ai';
3+
import { MockLanguageModelV1 } from 'ai/test';
4+
import express from 'express';
5+
import { createServer } from 'http';
6+
import { z } from 'zod';
7+
8+
async function run() {
9+
const app = express();
10+
11+
app.get('/api/chat', async (req, res) => {
12+
try {
13+
await generateText({
14+
model: new MockLanguageModelV1({
15+
doGenerate: async () => ({
16+
rawCall: { rawPrompt: null, rawSettings: {} },
17+
finishReason: 'stop',
18+
usage: { promptTokens: 10, completionTokens: 20 },
19+
text: 'Processing your request...',
20+
toolCalls: [
21+
{
22+
toolCallType: 'function',
23+
toolCallId: 'call-1',
24+
toolName: 'calculateTool',
25+
args: '{ "a": 1, "b": 2 }',
26+
},
27+
],
28+
}),
29+
}),
30+
experimental_telemetry: {
31+
functionId: 'Chat Assistant',
32+
recordInputs: true,
33+
recordOutputs: true,
34+
isEnabled: true,
35+
},
36+
tools: {
37+
calculateTool: tool({
38+
description: 'Calculate the result of a math problem. Returns a number.',
39+
parameters: z.object({
40+
a: z.number().describe('First number'),
41+
b: z.number().describe('Second number'),
42+
}),
43+
type: 'function',
44+
execute: async () => {
45+
throw new Error('Calculation service unavailable');
46+
},
47+
}),
48+
},
49+
maxSteps: 2,
50+
system: 'You are a helpful chat assistant.',
51+
prompt: 'What is 1 + 1?',
52+
});
53+
54+
res.json({ success: true });
55+
} catch (error) {
56+
res.status(500).json({ error: error.message });
57+
}
58+
});
59+
60+
Sentry.setupExpressErrorHandler(app);
61+
62+
const server = createServer(app);
63+
64+
// Start server and make request
65+
server.listen(0, () => {
66+
const port = server.address()?.port;
67+
// eslint-disable-next-line no-console
68+
console.log(JSON.stringify({ port }));
69+
70+
// Make the request that will trigger the error
71+
fetch(`http://localhost:${port}/api/chat`)
72+
.then(() => {
73+
server.close();
74+
})
75+
.catch(() => {
76+
server.close();
77+
});
78+
});
79+
}
80+
81+
run();

dev-packages/node-integration-tests/suites/tracing/vercelai/test.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,94 @@ describe('Vercel AI integration', () => {
416416
await createRunner().expect({ transaction: EXPECTED_TRANSACTION_DEFAULT_PII_TRUE }).start().completed();
417417
});
418418
});
419+
420+
createEsmAndCjsTests(__dirname, 'scenario-error.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
421+
test('Vercel AI errors should inherit parent trace context from manually created outer span', async () => {
422+
let capturedTransaction: any;
423+
let capturedEvent: any;
424+
425+
const runner = createRunner()
426+
.expect({
427+
transaction: (transaction: any) => {
428+
capturedTransaction = transaction;
429+
expect(transaction.transaction).toBe('outer span');
430+
},
431+
})
432+
.expect({
433+
event: (event: any) => {
434+
capturedEvent = event;
435+
436+
expect(event).toMatchObject({
437+
exception: {
438+
values: expect.arrayContaining([
439+
expect.objectContaining({
440+
type: 'AI_ToolExecutionError',
441+
value: 'Error executing tool calculateTool: Not implemented',
442+
}),
443+
]),
444+
},
445+
});
446+
},
447+
})
448+
.start();
449+
450+
await runner.completed();
451+
452+
const transactionTraceId = capturedTransaction?.contexts?.trace?.trace_id;
453+
const errorTraceId = capturedEvent?.contexts?.trace?.trace_id;
454+
455+
expect(transactionTraceId).toBeDefined();
456+
expect(errorTraceId).toBeDefined();
457+
expect(transactionTraceId).toMatch(/^[a-f0-9]{32}$/);
458+
expect(errorTraceId).toMatch(/^[a-f0-9]{32}$/);
459+
460+
expect(errorTraceId).toBe(transactionTraceId);
461+
});
462+
});
463+
464+
createEsmAndCjsTests(__dirname, 'scenario-express-error.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
465+
test('Vercel AI errors should inherit parent trace context from server HTTP request', async () => {
466+
let capturedTransaction: any;
467+
let capturedEvent: any;
468+
469+
const runner = createRunner()
470+
.withMockSentryServer()
471+
.expect({
472+
transaction: (transaction: any) => {
473+
capturedTransaction = transaction;
474+
// Express creates a transaction like "GET /api/chat"
475+
expect(transaction.transaction).toBe('GET /api/chat');
476+
},
477+
})
478+
.expect({
479+
event: (event: any) => {
480+
capturedEvent = event;
481+
482+
expect(event).toMatchObject({
483+
exception: {
484+
values: expect.arrayContaining([
485+
expect.objectContaining({
486+
type: 'AI_ToolExecutionError',
487+
value: 'Error executing tool calculateTool: Calculation service unavailable',
488+
}),
489+
]),
490+
},
491+
});
492+
},
493+
})
494+
.start();
495+
496+
await runner.completed();
497+
498+
const transactionTraceId = capturedTransaction?.contexts?.trace?.trace_id;
499+
const errorTraceId = capturedEvent?.contexts?.trace?.trace_id;
500+
501+
expect(transactionTraceId).toBeDefined();
502+
expect(errorTraceId).toBeDefined();
503+
expect(transactionTraceId).toMatch(/^[a-f0-9]{32}$/);
504+
expect(errorTraceId).toMatch(/^[a-f0-9]{32}$/);
505+
506+
expect(errorTraceId).toBe(transactionTraceId);
507+
});
508+
});
419509
});

0 commit comments

Comments
 (0)