Skip to content

Commit 96b56c5

Browse files
nicohrubeccodex
andauthored
test(node): Port Bedrock tests to span streaming (#25086)
Run the Bedrock Converse and InvokeModel integration test with default span streaming. Also replaces some consts with conventions equivalents. Part of #24138 --------- Co-authored-by: GPT-6 <codex@openai.com>
1 parent ce18d90 commit 96b56c5

2 files changed

Lines changed: 39 additions & 31 deletions

File tree

‎dev-packages/node-integration-tests/suites/aws-serverless/bedrock/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/aws-serverless';
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/aws-serverless/bedrock/test.ts‎

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,55 @@
1+
import {
2+
GEN_AI_OPERATION_NAME,
3+
GEN_AI_PROVIDER_NAME,
4+
GEN_AI_REQUEST_MAX_TOKENS,
5+
GEN_AI_REQUEST_MODEL,
6+
GEN_AI_REQUEST_TEMPERATURE,
7+
GEN_AI_REQUEST_TOP_P,
8+
GEN_AI_RESPONSE_FINISH_REASONS,
9+
GEN_AI_USAGE_INPUT_TOKENS,
10+
GEN_AI_USAGE_OUTPUT_TOKENS,
11+
SENTRY_OP,
12+
SENTRY_ORIGIN,
13+
} from '@sentry/conventions/attributes';
114
import type { SerializedStreamedSpanContainer } from '@sentry/core';
215
import { afterAll, describe, expect } from 'vitest';
316
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
417

518
const MODEL_ID = 'anthropic.claude-3-5-sonnet-20240620-v1:0';
619

720
function assertBedrockSpans(container: SerializedStreamedSpanContainer): void {
21+
const segment = container.items.find(span => span.is_segment && span.name === 'Test Transaction');
22+
expect(segment).toBeDefined();
23+
824
// Converse (non-streaming)
925
const converseSpan = container.items.find(span => span.name === `chat ${MODEL_ID}`);
10-
expect(converseSpan).toBeDefined();
1126
expect(converseSpan!.status).toBe('ok');
12-
expect(converseSpan!.attributes['sentry.origin'].value).toBe('auto.aws.aws_sdk');
13-
expect(converseSpan!.attributes['sentry.op'].value).toBe('gen_ai.chat');
14-
expect(converseSpan!.attributes['gen_ai.provider.name'].value).toBe('aws.bedrock');
15-
expect(converseSpan!.attributes['gen_ai.operation.name'].value).toBe('chat');
16-
expect(converseSpan!.attributes['gen_ai.request.model'].value).toBe(MODEL_ID);
17-
expect(converseSpan!.attributes['gen_ai.request.max_tokens'].value).toBe(100);
18-
expect(converseSpan!.attributes['gen_ai.request.temperature'].value).toBe(0.5);
19-
expect(converseSpan!.attributes['gen_ai.request.top_p'].value).toBe(0.9);
20-
expect(converseSpan!.attributes['gen_ai.usage.input_tokens'].value).toBe(12);
21-
expect(converseSpan!.attributes['gen_ai.usage.output_tokens'].value).toBe(8);
22-
expect(converseSpan!.attributes['gen_ai.response.finish_reasons'].value).toEqual(['end_turn']);
27+
expect(converseSpan!.attributes[SENTRY_ORIGIN].value).toBe('auto.aws.aws_sdk');
28+
expect(converseSpan!.attributes[SENTRY_OP].value).toBe('gen_ai.chat');
29+
expect(converseSpan!.attributes[GEN_AI_PROVIDER_NAME].value).toBe('aws.bedrock');
30+
expect(converseSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('chat');
31+
expect(converseSpan!.attributes[GEN_AI_REQUEST_MODEL].value).toBe(MODEL_ID);
32+
expect(converseSpan!.attributes[GEN_AI_REQUEST_MAX_TOKENS].value).toBe(100);
33+
expect(converseSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE].value).toBe(0.5);
34+
expect(converseSpan!.attributes[GEN_AI_REQUEST_TOP_P].value).toBe(0.9);
35+
expect(converseSpan!.attributes[GEN_AI_USAGE_INPUT_TOKENS].value).toBe(12);
36+
expect(converseSpan!.attributes[GEN_AI_USAGE_OUTPUT_TOKENS].value).toBe(8);
37+
expect(converseSpan!.attributes[GEN_AI_RESPONSE_FINISH_REASONS].value).toEqual(['end_turn']);
2338

2439
// InvokeModel (non-streaming, anthropic.claude request/response body)
2540
const invokeModelSpan = container.items.find(span => span.name === `generate_content ${MODEL_ID}`);
26-
expect(invokeModelSpan).toBeDefined();
2741
expect(invokeModelSpan!.status).toBe('ok');
28-
expect(invokeModelSpan!.attributes['sentry.origin'].value).toBe('auto.aws.aws_sdk');
29-
expect(invokeModelSpan!.attributes['sentry.op'].value).toBe('gen_ai.generate_content');
30-
expect(invokeModelSpan!.attributes['gen_ai.provider.name'].value).toBe('aws.bedrock');
31-
expect(invokeModelSpan!.attributes['gen_ai.operation.name'].value).toBe('generate_content');
32-
expect(invokeModelSpan!.attributes['gen_ai.request.model'].value).toBe(MODEL_ID);
33-
expect(invokeModelSpan!.attributes['gen_ai.request.max_tokens'].value).toBe(100);
34-
expect(invokeModelSpan!.attributes['gen_ai.request.temperature'].value).toBe(0.5);
35-
expect(invokeModelSpan!.attributes['gen_ai.request.top_p'].value).toBe(0.9);
36-
expect(invokeModelSpan!.attributes['gen_ai.usage.input_tokens'].value).toBe(15);
37-
expect(invokeModelSpan!.attributes['gen_ai.usage.output_tokens'].value).toBe(9);
38-
expect(invokeModelSpan!.attributes['gen_ai.response.finish_reasons'].value).toEqual(['end_turn']);
42+
expect(invokeModelSpan!.attributes[SENTRY_ORIGIN].value).toBe('auto.aws.aws_sdk');
43+
expect(invokeModelSpan!.attributes[SENTRY_OP].value).toBe('gen_ai.generate_content');
44+
expect(invokeModelSpan!.attributes[GEN_AI_PROVIDER_NAME].value).toBe('aws.bedrock');
45+
expect(invokeModelSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('generate_content');
46+
expect(invokeModelSpan!.attributes[GEN_AI_REQUEST_MODEL].value).toBe(MODEL_ID);
47+
expect(invokeModelSpan!.attributes[GEN_AI_REQUEST_MAX_TOKENS].value).toBe(100);
48+
expect(invokeModelSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE].value).toBe(0.5);
49+
expect(invokeModelSpan!.attributes[GEN_AI_REQUEST_TOP_P].value).toBe(0.9);
50+
expect(invokeModelSpan!.attributes[GEN_AI_USAGE_INPUT_TOKENS].value).toBe(15);
51+
expect(invokeModelSpan!.attributes[GEN_AI_USAGE_OUTPUT_TOKENS].value).toBe(9);
52+
expect(invokeModelSpan!.attributes[GEN_AI_RESPONSE_FINISH_REASONS].value).toEqual(['end_turn']);
3953
}
4054

4155
describe('awsIntegration - Bedrock', () => {
@@ -49,12 +63,7 @@ describe('awsIntegration - Bedrock', () => {
4963
'instrument.mjs',
5064
(createTestRunner, test) => {
5165
test('auto-instruments Bedrock Converse and InvokeModel', { timeout: 90_000 }, async () => {
52-
await createTestRunner()
53-
.ignore('event')
54-
.expect({ transaction: transaction => expect(transaction.transaction).toBe('Test Transaction') })
55-
.expect({ span: assertBedrockSpans })
56-
.start()
57-
.completed();
66+
await createTestRunner().ignore('event').expect({ span: assertBedrockSpans }).start().completed();
5867
});
5968
},
6069
{ additionalDependencies: { '@aws-sdk/client-bedrock-runtime': '^3.1046.0' } },

0 commit comments

Comments
 (0)