Skip to content

Commit 9c38fef

Browse files
nicohrubecclaude
andcommitted
test(node): Restore span-streaming coverage for AI integrations
The deleted truncation tests were the only ones exercising `traceLifecycle: 'stream'` for openai/anthropic/google-genai/langchain/ langgraph gen_ai spans. Re-point the (otherwise orphaned) scenario-span-streaming.mjs + instrument-streaming.mjs at a new non-truncation test per provider that asserts full gen_ai input messages are recorded under span streaming. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3e50614 commit 9c38fef

5 files changed

Lines changed: 96 additions & 3 deletions

File tree

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
2020
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
2121
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
22-
import { isOrchestrionEnabled } from '../../../utils';
22+
import { getStringAttributeValue, isOrchestrionEnabled } from '../../../utils';
2323
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
2424

2525
describe('Anthropic integration', () => {
@@ -678,4 +678,21 @@ describe('Anthropic integration', () => {
678678
});
679679
},
680680
);
681+
682+
createEsmAndCjsTests(__dirname, 'scenario-span-streaming.mjs', 'instrument-streaming.mjs', (createRunner, test) => {
683+
test('records full gen_ai input messages when span streaming is enabled', async () => {
684+
const longContent = 'A'.repeat(50_000);
685+
await createRunner()
686+
.expect({
687+
span: container => {
688+
const chatSpan = container.items.find(s =>
689+
getStringAttributeValue(s.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(longContent),
690+
);
691+
expect(chatSpan).toBeDefined();
692+
},
693+
})
694+
.start()
695+
.completed();
696+
});
697+
});
681698
});

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
2222
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
2323
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
24-
import { isOrchestrionEnabled } from '../../../utils';
24+
import { getStringAttributeValue, isOrchestrionEnabled } from '../../../utils';
2525

2626
const EXPECTED_ORIGIN = isOrchestrionEnabled() ? 'auto.ai.orchestrion.google_genai' : 'auto.ai.google_genai';
2727

@@ -459,4 +459,21 @@ describe('Google GenAI integration', () => {
459459
.completed();
460460
});
461461
});
462+
463+
createEsmAndCjsTests(__dirname, 'scenario-span-streaming.mjs', 'instrument-streaming.mjs', (createRunner, test) => {
464+
test('records full gen_ai input messages when span streaming is enabled', async () => {
465+
const longContent = 'A'.repeat(50_000);
466+
await createRunner()
467+
.expect({
468+
span: container => {
469+
const generateContentSpan = container.items.find(s =>
470+
getStringAttributeValue(s.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(longContent),
471+
);
472+
expect(generateContentSpan).toBeDefined();
473+
},
474+
})
475+
.start()
476+
.completed();
477+
});
478+
});
462479
});

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
2121
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
2222
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
23-
import { isOrchestrionEnabled } from '../../../utils';
23+
import { getStringAttributeValue, isOrchestrionEnabled } from '../../../utils';
2424
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
2525
import { createEsmTests } from '../../../utils/runner/createEsmAndCjsTests';
2626

@@ -400,4 +400,21 @@ describe('LangChain integration', () => {
400400
.completed();
401401
});
402402
});
403+
404+
createEsmAndCjsTests(__dirname, 'scenario-span-streaming.mjs', 'instrument-streaming.mjs', (createRunner, test) => {
405+
test('records full gen_ai input messages when span streaming is enabled', async () => {
406+
const longContent = 'A'.repeat(50_000);
407+
await createRunner()
408+
.expect({
409+
span: container => {
410+
const chatSpan = container.items.find(s =>
411+
getStringAttributeValue(s.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(longContent),
412+
);
413+
expect(chatSpan).toBeDefined();
414+
},
415+
})
416+
.start()
417+
.completed();
418+
});
419+
});
403420
});

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,4 +405,21 @@ describe('LangGraph integration', () => {
405405
.completed();
406406
});
407407
});
408+
409+
createEsmAndCjsTests(__dirname, 'scenario-span-streaming.mjs', 'instrument-streaming.mjs', (createRunner, test) => {
410+
test('records full gen_ai input messages when span streaming is enabled', async () => {
411+
const longContent = 'A'.repeat(50_000);
412+
await createRunner()
413+
.expect({
414+
span: container => {
415+
const chatSpan = container.items.find(s =>
416+
getStringAttributeValue(s.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(longContent),
417+
);
418+
expect(chatSpan).toBeDefined();
419+
},
420+
})
421+
.start()
422+
.completed();
423+
});
424+
});
408425
});

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,4 +1421,29 @@ describe('OpenAI integration', () => {
14211421
.completed();
14221422
});
14231423
});
1424+
1425+
createEsmAndCjsTests(__dirname, 'scenario-span-streaming.mjs', 'instrument-streaming.mjs', (createRunner, test) => {
1426+
test('records full gen_ai input messages when span streaming is enabled', async () => {
1427+
const longContent = 'A'.repeat(50_000);
1428+
const longStringInput = 'B'.repeat(50_000);
1429+
await createRunner()
1430+
.expect({
1431+
span: container => {
1432+
const spans = container.items;
1433+
1434+
const chatSpan = spans.find(s =>
1435+
getStringAttributeValue(s.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(longContent),
1436+
);
1437+
expect(chatSpan).toBeDefined();
1438+
1439+
const responsesSpan = spans.find(s =>
1440+
getStringAttributeValue(s.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(longStringInput),
1441+
);
1442+
expect(responsesSpan).toBeDefined();
1443+
},
1444+
})
1445+
.start()
1446+
.completed();
1447+
});
1448+
});
14241449
});

0 commit comments

Comments
 (0)