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
Expand Up @@ -20,7 +20,6 @@ import {
GEN_AI_USAGE_TOTAL_TOKENS,
} from '@sentry/conventions/attributes';
import { GEN_AI_REQUEST_STREAM_ATTRIBUTE } from '../../../../../packages/server-utils/src/ai/core/gen-ai-attributes';
import { isOrchestrionEnabled } from '../../../utils';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

describe('Anthropic integration', () => {
Expand All @@ -38,25 +37,13 @@ describe('Anthropic integration', () => {
expect(modelsSpan!.status).toBe('ok');
};

const EXPECTED_MODEL_ERROR = {
exception: {
values: [
{
type: 'Error',
value: '404 Model not found',
},
],
},
};

const EXPECTED_STREAM_EVENT_HANDLER_MESSAGE = {
message: 'stream event from user-added event listener captured',
};

createEsmAndCjsTests(__dirname, 'scenario-with-response.mjs', 'instrument.mjs', (createRunner, test) => {
test('preserves .withResponse() and .asResponse() for non-streaming and streaming', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'main',
Expand Down Expand Up @@ -92,15 +79,7 @@ describe('Anthropic integration', () => {

createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates anthropic related spans with genAI recording disabled', async () => {
const runner = createRunner();

// The orchestrion path only marks the errored span; unlike the OTel path it does not
// capture the handled `error-model` rejection as an event.
if (!isOrchestrionEnabled()) {
runner.expect({ event: EXPECTED_MODEL_ERROR });
}

await runner
await createRunner()
.expect({ transaction: expectModelsSpanOnTransaction })
.expect({
span: container => {
Expand Down Expand Up @@ -142,15 +121,7 @@ describe('Anthropic integration', () => {

createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('creates anthropic related spans with genAI recording enabled', async () => {
const runner = createRunner();

// The orchestrion path only marks the errored span; unlike the OTel path it does not
// capture the handled `error-model` rejection as an event.
if (!isOrchestrionEnabled()) {
runner.expect({ event: EXPECTED_MODEL_ERROR });
}

await runner
await createRunner()
.expect({ transaction: expectModelsSpanOnTransaction })
.expect({
span: container => {
Expand Down Expand Up @@ -220,15 +191,7 @@ describe('Anthropic integration', () => {

createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-with-options.mjs', (createRunner, test) => {
test('creates anthropic related spans with custom options', async () => {
const runner = createRunner();

// The orchestrion path only marks the errored span; unlike the OTel path it does not
// capture the handled `error-model` rejection as an event.
if (!isOrchestrionEnabled()) {
runner.expect({ event: EXPECTED_MODEL_ERROR });
}

await runner
await createRunner()
.expect({
transaction: event => {
expect(event.transaction).toBe('main');
Expand Down Expand Up @@ -296,7 +259,6 @@ describe('Anthropic integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-stream.mjs', 'instrument.mjs', (createRunner, test) => {
test('streams produce spans with token usage and metadata (PII false)', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: EXPECTED_STREAM_SPANS_PII_FALSE })
.expect({
span: container => {
Expand Down Expand Up @@ -350,7 +312,6 @@ describe('Anthropic integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-stream.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('streams record response text when PII true', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: EXPECTED_STREAM_SPANS_PII_TRUE })
.expect({
span: container => {
Expand Down Expand Up @@ -401,7 +362,6 @@ describe('Anthropic integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-stream-nested-create.mjs', 'instrument.mjs', (createRunner, test) => {
test('traces a create() invoked from a stream event handler (dedup does not over-suppress)', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -432,7 +392,6 @@ describe('Anthropic integration', () => {
const EXPECTED_TOOL_CALLS_JSON =
'[{"type":"tool_use","id":"tool_weather_1","name":"weather","input":{"city":"Paris"}}]';
await createRunner()
.ignore('event')
.expect({
transaction: {},
})
Expand Down Expand Up @@ -462,7 +421,6 @@ describe('Anthropic integration', () => {
const EXPECTED_TOOL_CALLS_JSON =
'[{"type":"tool_use","id":"tool_weather_2","name":"weather","input":{"city":"Paris"}}]';
await createRunner()
.ignore('event')
.expect({
transaction: {},
})
Expand Down Expand Up @@ -503,6 +461,8 @@ describe('Anthropic integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-stream-errors.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('handles streaming errors correctly', async () => {
await createRunner()
// Anthropic surfaces stream errors as events on a resolved stream rather than by rejecting,
// so the instrumentation still reports them; the caller never sees them as a thrown error.
.ignore('event')
.expect({ transaction: EXPECTED_STREAM_ERROR_SPANS })
.expect({
Expand Down Expand Up @@ -551,7 +511,6 @@ describe('Anthropic integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-errors.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('handles tool errors and model retrieval errors correctly', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: event => {
expect(event.transaction).toBe('main');
Expand Down Expand Up @@ -590,7 +549,6 @@ describe('Anthropic integration', () => {
test('extracts system instructions from messages', async () => {
const expectedInstructions = JSON.stringify([{ type: 'text', content: 'You are a helpful assistant' }]);
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'main',
Expand All @@ -614,7 +572,6 @@ describe('Anthropic integration', () => {
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-span-streaming.mjs', (createRunner, test) => {
test('creates anthropic related spans with span streaming enabled', async () => {
await createRunner()
.ignore('event')
.expect({
span: container => {
const completionSpan = container.items.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates google genai related spans with genAI recording disabled', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -86,7 +85,6 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('creates google genai related spans with genAI recording enabled', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -137,7 +135,6 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-with-options.mjs', (createRunner, test) => {
test('creates google genai related spans with custom options', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -174,7 +171,6 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-tools.mjs', 'instrument-with-options.mjs', (createRunner, test) => {
test('creates google genai related spans with tool calls', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -233,6 +229,7 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-streaming.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates google genai streaming spans with genAI recording disabled', async () => {
await createRunner()
// Blocked content is reported from within the stream, not thrown to the caller.
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
Expand Down Expand Up @@ -289,6 +286,7 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-streaming.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('creates google genai streaming spans with genAI recording enabled', async () => {
await createRunner()
// Blocked content is reported from within the stream, not thrown to the caller.
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
Expand Down Expand Up @@ -348,7 +346,6 @@ describe('Google GenAI integration', () => {
(createRunner, test) => {
test('extracts system instructions from messages', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand All @@ -372,7 +369,6 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-embeddings.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates google genai embeddings spans with genAI recording disabled', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -411,7 +407,6 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-embeddings.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('creates google genai embeddings spans with genAI recording enabled', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -458,7 +453,6 @@ describe('Google GenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-span-streaming.mjs', (createRunner, test) => {
test('creates google genai related spans with span streaming enabled', async () => {
await createRunner()
.ignore('event')
.expect({
span: container => {
const generateContentSpan = container.items.find(span => span.name === 'generate_content gemini-1.5-flash');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ describe('OpenAI Tool Calls integration', () => {
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates openai tool calls related spans with genAI recording disabled', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -326,7 +325,6 @@ describe('OpenAI Tool Calls integration', () => {
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('creates openai tool calls related spans with genAI recording enabled', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-chat.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates openai related spans with genAI recording disabled', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -333,7 +332,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-chat.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('creates openai related spans with genAI recording enabled', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -681,7 +679,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-chat.mjs', 'instrument-with-options.mjs', (createRunner, test) => {
test('creates openai related spans with custom options', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -726,7 +723,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-embeddings.mjs', 'instrument.mjs', (createRunner, test) => {
test('creates openai related spans with genAI recording disabled', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'main',
Expand Down Expand Up @@ -859,7 +855,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-embeddings.mjs', 'instrument-with-pii.mjs', (createRunner, test) => {
test('creates openai related spans with genAI recording enabled', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'main',
Expand Down Expand Up @@ -1089,7 +1084,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-conversation.mjs', 'instrument.mjs', (createRunner, test) => {
test('captures conversation ID from Conversations API and previous_response_id', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'conversation-test',
Expand Down Expand Up @@ -1209,7 +1203,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-manual-conversation-id.mjs', 'instrument.mjs', (createRunner, test) => {
test('attaches manual conversation ID set via setConversationId() to all chat spans', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'chat-with-manual-conversation-id',
Expand Down Expand Up @@ -1242,7 +1235,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-separate-scope-1.mjs', 'instrument.mjs', (createRunner, test) => {
test('isolates conversation IDs across separate scopes - conversation 1', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'GET /chat/conversation-1',
Expand Down Expand Up @@ -1274,7 +1266,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-separate-scope-2.mjs', 'instrument.mjs', (createRunner, test) => {
test('isolates conversation IDs across separate scopes - conversation 2', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'GET /chat/conversation-2',
Expand Down Expand Up @@ -1310,7 +1301,6 @@ describe('OpenAI integration', () => {
(createRunner, test) => {
test('extracts system instructions from messages', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'main',
Expand All @@ -1337,7 +1327,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-with-response.mjs', 'instrument.mjs', (createRunner, test) => {
test('preserves .withResponse() method and works correctly', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'main',
Expand Down Expand Up @@ -1368,7 +1357,6 @@ describe('OpenAI integration', () => {
createEsmAndCjsTests(__dirname, 'scenario-chat.mjs', 'instrument-span-streaming.mjs', (createRunner, test) => {
test('creates openai related spans with span streaming enabled', async () => {
await createRunner()
.ignore('event')
.expect({
span: container => {
const chatCompletionSpan = container.items.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('OpenAI integration (V6)', () => {
(createRunner, test) => {
test('creates openai related spans with genAI recording disabled (v6)', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -346,7 +345,6 @@ describe('OpenAI integration (V6)', () => {
(createRunner, test) => {
test('creates openai related spans with genAI recording enabled (v6)', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -704,7 +702,6 @@ describe('OpenAI integration (V6)', () => {
(createRunner, test) => {
test('creates openai related spans with custom options (v6)', async () => {
await createRunner()
.ignore('event')
.expect({ transaction: { transaction: 'main' } })
.expect({
span: container => {
Expand Down Expand Up @@ -767,7 +764,6 @@ describe('OpenAI integration (V6)', () => {
(createRunner, test) => {
test('creates openai related spans with genAI recording disabled (v6)', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'main',
Expand Down Expand Up @@ -910,7 +906,6 @@ describe('OpenAI integration (V6)', () => {
(createRunner, test) => {
test('creates openai related spans with genAI recording enabled (v6)', async () => {
await createRunner()
.ignore('event')
.expect({
transaction: {
transaction: 'main',
Expand Down
Loading