Skip to content

Commit ce18d90

Browse files
nicohrubeccodex
andauthored
test(node): Port OpenAI integration tests to span streaming (#25081)
Port the OpenAI v5/v6/v7, Azure and tool-call integration tests to the default span-streaming lifecycle. I know this looks huge but it really isn't. This just uses the new `collectStreamedSpansUntilSegment` helper and that changes indentation that's why the diff is so large mostly. Part of #24138 --------- Co-authored-by: GPT-6 <codex@openai.com>
1 parent 5c75501 commit ce18d90

17 files changed

Lines changed: 2564 additions & 2899 deletions

‎dev-packages/node-integration-tests/suites/tracing/openai/instrument-root-span.mjs‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎dev-packages/node-integration-tests/suites/tracing/openai/instrument-span-streaming.mjs‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎dev-packages/node-integration-tests/suites/tracing/openai/instrument-with-options.mjs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
22
import { loggingTransport } from '@sentry-internal/node-integration-tests';
33

44
Sentry.init({
5-
traceLifecycle: 'static',
65
dsn: 'https://public@dsn.ingest.sentry.io/1337',
76
release: '1.0',
87
tracesSampleRate: 1.0,
@@ -14,10 +13,4 @@ Sentry.init({
1413
recordOutputs: true,
1514
}),
1615
],
17-
beforeSendTransaction: event => {
18-
if (event.transaction.includes('/openai/')) {
19-
return null;
20-
}
21-
return event;
22-
},
2316
});

‎dev-packages/node-integration-tests/suites/tracing/openai/instrument-with-pii.mjs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@ import * as Sentry from '@sentry/node';
22
import { loggingTransport } from '@sentry-internal/node-integration-tests';
33

44
Sentry.init({
5-
traceLifecycle: 'static',
65
dsn: 'https://public@dsn.ingest.sentry.io/1337',
76
release: '1.0',
87
tracesSampleRate: 1.0,
98
dataCollection: { genAI: { inputs: true, outputs: true } },
109
transport: loggingTransport,
11-
beforeSendTransaction: event => {
12-
if (event.transaction.includes('/openai/')) {
13-
return null;
14-
}
15-
return event;
16-
},
1710
});

‎dev-packages/node-integration-tests/suites/tracing/openai/instrument.mjs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@ import * as Sentry from '@sentry/node';
22
import { loggingTransport } from '@sentry-internal/node-integration-tests';
33

44
Sentry.init({
5-
traceLifecycle: 'static',
65
dsn: 'https://public@dsn.ingest.sentry.io/1337',
76
release: '1.0',
87
tracesSampleRate: 1.0,
98
dataCollection: { genAI: { inputs: false, outputs: false } },
109
transport: loggingTransport,
11-
beforeSendTransaction: event => {
12-
if (event.transaction.includes('/openai/')) {
13-
return null;
14-
}
15-
return event;
16-
},
1710
});

‎dev-packages/node-integration-tests/suites/tracing/openai/openai-tool-calls/instrument-with-pii.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
22
import { loggingTransport } from '@sentry-internal/node-integration-tests';
33

44
Sentry.init({
5-
traceLifecycle: 'static',
65
dsn: 'https://public@dsn.ingest.sentry.io/1337',
76
release: '1.0',
87
tracesSampleRate: 1.0,

‎dev-packages/node-integration-tests/suites/tracing/openai/openai-tool-calls/instrument.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as Sentry from '@sentry/node';
22
import { loggingTransport } from '@sentry-internal/node-integration-tests';
33

44
Sentry.init({
5-
traceLifecycle: 'static',
65
dsn: 'https://public@dsn.ingest.sentry.io/1337',
76
release: '1.0',
87
tracesSampleRate: 1.0,

‎dev-packages/node-integration-tests/suites/tracing/openai/openai-tool-calls/test.ts‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ describe('OpenAI Tool Calls integration', () => {
7979
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
8080
test('creates openai tool calls related spans with genAI recording disabled', async () => {
8181
await createRunner()
82-
.expect({ transaction: { transaction: 'main' } })
8382
.expect({
8483
span: container => {
85-
expect(container.items).toHaveLength(4);
86-
const chatToolsSpan = container.items.find(
84+
const segment = container.items.find(span => span.is_segment && span.name === 'main');
85+
expect(segment).toBeDefined();
86+
const spans = container.items.filter(span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.ai.openai');
87+
expect(spans).toHaveLength(4);
88+
const chatToolsSpan = spans.find(
8789
span => span.attributes[GEN_AI_RESPONSE_ID]?.value === 'chatcmpl-tools-123',
8890
);
89-
expect(chatToolsSpan).toBeDefined();
9091
expect(chatToolsSpan!.name).toBe('chat gpt-4');
9192
expect(chatToolsSpan!.status).toBe('ok');
9293
expect(chatToolsSpan!.attributes[GEN_AI_OPERATION_NAME]).toEqual({
@@ -133,10 +134,9 @@ describe('OpenAI Tool Calls integration', () => {
133134
value: 40,
134135
});
135136

136-
const streamingChatToolsSpan = container.items.find(
137+
const streamingChatToolsSpan = spans.find(
137138
span => span.attributes[GEN_AI_RESPONSE_ID]?.value === 'chatcmpl-stream-tools-123',
138139
);
139-
expect(streamingChatToolsSpan).toBeDefined();
140140
expect(streamingChatToolsSpan!.name).toBe('chat gpt-4');
141141
expect(streamingChatToolsSpan!.status).toBe('ok');
142142
expect(streamingChatToolsSpan!.attributes[GEN_AI_OPERATION_NAME]).toEqual({
@@ -193,10 +193,9 @@ describe('OpenAI Tool Calls integration', () => {
193193
value: 40,
194194
});
195195

196-
const responsesToolsSpan = container.items.find(
196+
const responsesToolsSpan = spans.find(
197197
span => span.attributes[GEN_AI_RESPONSE_ID]?.value === 'resp_tools_789',
198198
);
199-
expect(responsesToolsSpan).toBeDefined();
200199
expect(responsesToolsSpan!.name).toBe('chat gpt-4');
201200
expect(responsesToolsSpan!.status).toBe('ok');
202201
expect(responsesToolsSpan!.attributes[GEN_AI_OPERATION_NAME]).toEqual({
@@ -246,10 +245,9 @@ describe('OpenAI Tool Calls integration', () => {
246245
value: 20,
247246
});
248247

249-
const streamingResponsesToolsSpan = container.items.find(
248+
const streamingResponsesToolsSpan = spans.find(
250249
span => span.attributes[GEN_AI_RESPONSE_ID]?.value === 'resp_stream_tools_789',
251250
);
252-
expect(streamingResponsesToolsSpan).toBeDefined();
253251
expect(streamingResponsesToolsSpan!.name).toBe('chat gpt-4');
254252
expect(streamingResponsesToolsSpan!.status).toBe('ok');
255253
expect(streamingResponsesToolsSpan!.attributes[GEN_AI_OPERATION_NAME]).toEqual({
@@ -315,14 +313,15 @@ describe('OpenAI Tool Calls integration', () => {
315313
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
316314
test('creates openai tool calls related spans with genAI recording enabled', async () => {
317315
await createRunner()
318-
.expect({ transaction: { transaction: 'main' } })
319316
.expect({
320317
span: container => {
321-
expect(container.items).toHaveLength(4);
322-
const chatToolsSpan = container.items.find(
318+
const segment = container.items.find(span => span.is_segment && span.name === 'main');
319+
expect(segment).toBeDefined();
320+
const spans = container.items.filter(span => span.attributes[SENTRY_ORIGIN]?.value === 'auto.ai.openai');
321+
expect(spans).toHaveLength(4);
322+
const chatToolsSpan = spans.find(
323323
span => span.attributes[GEN_AI_RESPONSE_ID]?.value === 'chatcmpl-tools-123',
324324
);
325-
expect(chatToolsSpan).toBeDefined();
326325
expect(chatToolsSpan!.name).toBe('chat gpt-4');
327326
expect(chatToolsSpan!.status).toBe('ok');
328327
expect(chatToolsSpan!.attributes[GEN_AI_OPERATION_NAME]).toEqual({
@@ -383,10 +382,9 @@ describe('OpenAI Tool Calls integration', () => {
383382
value: 40,
384383
});
385384

386-
const streamingChatToolsSpan = container.items.find(
385+
const streamingChatToolsSpan = spans.find(
387386
span => span.attributes[GEN_AI_RESPONSE_ID]?.value === 'chatcmpl-stream-tools-123',
388387
);
389-
expect(streamingChatToolsSpan).toBeDefined();
390388
expect(streamingChatToolsSpan!.name).toBe('chat gpt-4');
391389
expect(streamingChatToolsSpan!.status).toBe('ok');
392390
expect(streamingChatToolsSpan!.attributes[GEN_AI_OPERATION_NAME]).toEqual({
@@ -454,10 +452,9 @@ describe('OpenAI Tool Calls integration', () => {
454452
value: 40,
455453
});
456454

457-
const responsesToolsSpan = container.items.find(
455+
const responsesToolsSpan = spans.find(
458456
span => span.attributes[GEN_AI_RESPONSE_ID]?.value === 'resp_tools_789',
459457
);
460-
expect(responsesToolsSpan).toBeDefined();
461458
expect(responsesToolsSpan!.name).toBe('chat gpt-4');
462459
expect(responsesToolsSpan!.status).toBe('ok');
463460
expect(responsesToolsSpan!.attributes[GEN_AI_OPERATION_NAME]).toEqual({
@@ -518,10 +515,9 @@ describe('OpenAI Tool Calls integration', () => {
518515
value: 20,
519516
});
520517

521-
const streamingResponsesToolsSpan = container.items.find(
518+
const streamingResponsesToolsSpan = spans.find(
522519
span => span.attributes[GEN_AI_RESPONSE_ID]?.value === 'resp_stream_tools_789',
523520
);
524-
expect(streamingResponsesToolsSpan).toBeDefined();
525521
expect(streamingResponsesToolsSpan!.name).toBe('chat gpt-4');
526522
expect(streamingResponsesToolsSpan!.status).toBe('ok');
527523
expect(streamingResponsesToolsSpan!.attributes[GEN_AI_OPERATION_NAME]).toEqual({

0 commit comments

Comments
 (0)