Skip to content
Merged
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
4 changes: 3 additions & 1 deletion dev-packages/node-integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"clean:script": "node scripts/clean.js",
"lint": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --type-aware",
"lint:fix": "OXLINT_TSGOLINT_DANGEROUSLY_SUPPRESS_PROGRAM_DIAGNOSTICS=true oxlint . --fix --type-aware",
"type-check": "tsc",
"type-check": "run-s type-check:src type-check:test",
"type-check:src": "tsc --noEmit",
"type-check:test": "tsc -p tsconfig.test.json --noEmit",
"test": "vitest run",
"test:orchestrion": "INJECT_ORCHESTRION=true yarn test",
"test:watch": "yarn test --watch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { isOrchestrionEnabled } from '../../../utils';
import { getStringAttributeValue, isOrchestrionEnabled } from '../../../utils';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

describe('Anthropic integration', () => {
Expand Down Expand Up @@ -580,7 +580,7 @@ describe('Anthropic integration', () => {
{ role: 'user', content: 'This is a small message that fits within the limit' },
]);
const truncatedSpan = container.items.find(span =>
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.match(
getStringAttributeValue(span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.match(
/^\[\{"role":"user","content":"C+"\}\]$/,
),
);
Expand Down Expand Up @@ -750,7 +750,9 @@ describe('Anthropic integration', () => {
const spans = container.items;

const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes(streamingLongContent),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
streamingLongContent,
),
);
expect(chatSpan).toBeDefined();
},
Expand All @@ -774,12 +776,14 @@ describe('Anthropic integration', () => {
// With explicit enableTruncation: true, content should be truncated despite streaming.
// Find the chat span by matching the start of the truncated content (the 'A' repeated messages).
const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.startsWith('[{"role":"user","content":"AAAA'),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.startsWith(
'[{"role":"user","content":"AAAA',
),
);
expect(chatSpan).toBeDefined();
expect(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value.length).toBeLessThan(
streamingLongContent.length,
);
expect(
(getStringAttributeValue(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value) ?? '').length,
).toBeLessThan(streamingLongContent.length);
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
import { isOrchestrionEnabled } from '../../../utils';
import { getStringAttributeValue, isOrchestrionEnabled } from '../../../utils';

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

Expand Down Expand Up @@ -360,7 +360,7 @@ describe('Google GenAI integration', () => {
span: container => {
expect(container.items).toHaveLength(2);
const truncatedSpan = container.items.find(span =>
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.match(
getStringAttributeValue(span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.match(
/^\[\{"role":"user","parts":\[\{"text":"C+"\}\]\}\]$/,
),
);
Expand Down Expand Up @@ -551,7 +551,9 @@ describe('Google GenAI integration', () => {
const spans = container.items;

const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes(streamingLongContent),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
streamingLongContent,
),
);
expect(chatSpan).toBeDefined();
},
Expand All @@ -575,14 +577,14 @@ describe('Google GenAI integration', () => {
// With explicit enableTruncation: true, content should be truncated despite streaming.
// Find the chat span by matching the start of the truncated content (the 'A' repeated messages).
const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.startsWith(
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.startsWith(
'[{"role":"user","parts":[{"text":"AAAA',
),
);
expect(chatSpan).toBeDefined();
expect(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value.length).toBeLessThan(
streamingLongContent.length,
);
expect(
(getStringAttributeValue(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value) ?? '').length,
).toBeLessThan(streamingLongContent.length);
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { isOrchestrionEnabled } from '../../../utils';
import { getStringAttributeValue, isOrchestrionEnabled } from '../../../utils';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
import { createEsmTests } from '../../../utils/runner/createEsmAndCjsTests';

Expand Down Expand Up @@ -222,7 +222,7 @@ describe('LangChain integration', () => {
const arrayInputSpan = container.items.find(
span =>
span.attributes[GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE]?.value === 2 &&
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.match(
getStringAttributeValue(span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.match(
/^\[\{"role":"user","content":"C+"\}\]$/,
),
);
Expand Down Expand Up @@ -495,7 +495,9 @@ describe('LangChain integration', () => {
const spans = container.items;

const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes(streamingLongContent),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
streamingLongContent,
),
);
expect(chatSpan).toBeDefined();
},
Expand All @@ -518,12 +520,14 @@ describe('LangChain integration', () => {

// With explicit enableTruncation: true, content should be truncated despite streaming.
const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.startsWith('[{"role":"user","content":"AAAA'),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.startsWith(
'[{"role":"user","content":"AAAA',
),
);
expect(chatSpan).toBeDefined();
expect(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value.length).toBeLessThan(
streamingLongContent.length,
);
expect(
(getStringAttributeValue(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value) ?? '').length,
).toBeLessThan(streamingLongContent.length);
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
} from '../../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { conditionalTest, isOrchestrionEnabled } from '../../../../utils';
import { conditionalTest, getStringAttributeValue, isOrchestrionEnabled } from '../../../../utils';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';
import { createEsmTests } from '../../../../utils/runner/createEsmAndCjsTests';

Expand Down Expand Up @@ -238,7 +238,7 @@ conditionalTest({ min: 20 })('LangChain integration (v1)', () => {
const arrayInputSpan = container.items.find(
span =>
span.attributes[GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE]?.value === 2 &&
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.match(
getStringAttributeValue(span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.match(
/^\[\{"role":"user","content":"C+"\}\]$/,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { getStringAttributeValue } from '../../../utils';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

describe('LangGraph integration', () => {
Expand Down Expand Up @@ -77,7 +78,9 @@ describe('LangGraph integration', () => {
expect(createAgentSpan!.attributes['sentry.op'].value).toBe('gen_ai.create_agent');

const weatherTodaySpan = container.items.find(span =>
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes('What is the weather today?'),
getStringAttributeValue(span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
'What is the weather today?',
),
);
expect(weatherTodaySpan).toBeDefined();
expect(weatherTodaySpan!.name).toBe('invoke_agent weather_assistant');
Expand All @@ -86,7 +89,9 @@ describe('LangGraph integration', () => {
expect(weatherTodaySpan!.attributes['sentry.origin'].value).toBe('auto.ai.langgraph');

const weatherDetailsSpan = container.items.find(span =>
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes('Tell me about the weather'),
getStringAttributeValue(span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
'Tell me about the weather',
),
);
expect(weatherDetailsSpan).toBeDefined();
expect(weatherDetailsSpan!.name).toBe('invoke_agent weather_assistant');
Expand Down Expand Up @@ -319,7 +324,9 @@ describe('LangGraph integration', () => {
const spans = container.items;

const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes(streamingLongContent),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
streamingLongContent,
),
);
expect(chatSpan).toBeDefined();
},
Expand All @@ -342,12 +349,14 @@ describe('LangGraph integration', () => {

// With explicit enableTruncation: true, content should be truncated despite streaming.
const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.startsWith('[{"role":"user","content":"AAAA'),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.startsWith(
'[{"role":"user","content":"AAAA',
),
);
expect(chatSpan).toBeDefined();
expect(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value.length).toBeLessThan(
streamingLongContent.length,
);
expect(
(getStringAttributeValue(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value) ?? '').length,
).toBeLessThan(streamingLongContent.length);
},
})
.start()
Expand Down
35 changes: 22 additions & 13 deletions dev-packages/node-integration-tests/suites/tracing/openai/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE,
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
} from '../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { isOrchestrionEnabled } from '../../../utils';
import { getStringAttributeValue, isOrchestrionEnabled } from '../../../utils';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

describe('OpenAI integration', () => {
Expand Down Expand Up @@ -1193,7 +1193,7 @@ describe('OpenAI integration', () => {
span: container => {
expect(container.items).toHaveLength(2);
const truncatedMessageSpan = container.items.find(span =>
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.match(
getStringAttributeValue(span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.match(
/^\[\{"role":"user","content":"C+"\}\]$/,
),
);
Expand Down Expand Up @@ -1651,7 +1651,9 @@ describe('OpenAI integration', () => {
span: container => {
expect(container.items).toHaveLength(2);
const multipleImagesSpan = container.items.find(span =>
span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes('https://example.com/image.png'),
getStringAttributeValue(span.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
'https://example.com/image.png',
),
);
expect(multipleImagesSpan).toBeDefined();
expect(multipleImagesSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value).toContain(
Expand All @@ -1675,12 +1677,16 @@ describe('OpenAI integration', () => {
const spans = container.items;

const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes(streamingLongContent),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
streamingLongContent,
),
);
expect(chatSpan).toBeDefined();

const responsesSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes(streamingLongString),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
streamingLongString,
),
);
expect(responsesSpan).toBeDefined();
},
Expand All @@ -1704,21 +1710,24 @@ describe('OpenAI integration', () => {
// With explicit enableTruncation: true, content should be truncated despite streaming.
// Truncation keeps only the last message (50k 'A's) and crops it to the byte limit.
const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.startsWith('[{"role":"user","content":"AAAA'),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.startsWith(
'[{"role":"user","content":"AAAA',
),
);
expect(chatSpan).toBeDefined();
expect(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value.length).toBeLessThan(
streamingLongContent.length,
);
expect(
(getStringAttributeValue(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value) ?? '').length,
).toBeLessThan(streamingLongContent.length);

// The responses API string input (50k 'B's) should also be truncated.
const responsesSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.startsWith('BBB'),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.startsWith('BBB'),
);
expect(responsesSpan).toBeDefined();
expect(responsesSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value.length).toBeLessThan(
streamingLongString.length,
);
expect(
(getStringAttributeValue(responsesSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value) ?? '')
.length,
).toBeLessThan(streamingLongString.length);
},
})
.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
GEN_AI_USAGE_TOTAL_TOKENS_ATTRIBUTE,
} from '../../../../../../packages/core/src/tracing/ai/gen-ai-attributes';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../../utils/runner';
import { isOrchestrionEnabled } from '../../../../utils';
import { getStringAttributeValue, isOrchestrionEnabled } from '../../../../utils';

/**
* Helper to match a typed attribute value in a SerializedStreamedSpan.
Expand Down Expand Up @@ -314,7 +314,9 @@ describe.skipIf(isOrchestrionEnabled())('Vercel AI integration (streaming v4)',
const spans = container.items;

const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.includes(streamingLongContent),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.includes(
streamingLongContent,
),
);
expect(chatSpan).toBeDefined();
},
Expand All @@ -333,12 +335,14 @@ describe.skipIf(isOrchestrionEnabled())('Vercel AI integration (streaming v4)',

// With explicit enableTruncation: true, content should be truncated despite streaming.
const chatSpan = spans.find(s =>
s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value?.startsWith('[{"role":"user","content":"AAAA'),
getStringAttributeValue(s.attributes?.[GEN_AI_INPUT_MESSAGES_ATTRIBUTE]?.value)?.startsWith(
'[{"role":"user","content":"AAAA',
),
);
expect(chatSpan).toBeDefined();
expect(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value.length).toBeLessThan(
streamingLongContent.length,
);
expect(
(getStringAttributeValue(chatSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value) ?? '').length,
).toBeLessThan(streamingLongContent.length);
},
})
.start()
Expand Down
Loading
Loading