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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as Sentry from '@sentry/aws-serverless';
import { loggingTransport } from '@sentry-internal/node-integration-tests';

Sentry.init({
traceLifecycle: 'static',
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,55 @@
import {
GEN_AI_OPERATION_NAME,
GEN_AI_PROVIDER_NAME,
GEN_AI_REQUEST_MAX_TOKENS,
GEN_AI_REQUEST_MODEL,
GEN_AI_REQUEST_TEMPERATURE,
GEN_AI_REQUEST_TOP_P,
GEN_AI_RESPONSE_FINISH_REASONS,
GEN_AI_USAGE_INPUT_TOKENS,
GEN_AI_USAGE_OUTPUT_TOKENS,
SENTRY_OP,
SENTRY_ORIGIN,
} from '@sentry/conventions/attributes';
import type { SerializedStreamedSpanContainer } from '@sentry/core';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';

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

function assertBedrockSpans(container: SerializedStreamedSpanContainer): void {
const segment = container.items.find(span => span.is_segment && span.name === 'Test Transaction');
expect(segment).toBeDefined();

// Converse (non-streaming)
const converseSpan = container.items.find(span => span.name === `chat ${MODEL_ID}`);
expect(converseSpan).toBeDefined();
expect(converseSpan!.status).toBe('ok');
expect(converseSpan!.attributes['sentry.origin'].value).toBe('auto.aws.aws_sdk');
expect(converseSpan!.attributes['sentry.op'].value).toBe('gen_ai.chat');
expect(converseSpan!.attributes['gen_ai.provider.name'].value).toBe('aws.bedrock');
expect(converseSpan!.attributes['gen_ai.operation.name'].value).toBe('chat');
expect(converseSpan!.attributes['gen_ai.request.model'].value).toBe(MODEL_ID);
expect(converseSpan!.attributes['gen_ai.request.max_tokens'].value).toBe(100);
expect(converseSpan!.attributes['gen_ai.request.temperature'].value).toBe(0.5);
expect(converseSpan!.attributes['gen_ai.request.top_p'].value).toBe(0.9);
expect(converseSpan!.attributes['gen_ai.usage.input_tokens'].value).toBe(12);
expect(converseSpan!.attributes['gen_ai.usage.output_tokens'].value).toBe(8);
expect(converseSpan!.attributes['gen_ai.response.finish_reasons'].value).toEqual(['end_turn']);
expect(converseSpan!.attributes[SENTRY_ORIGIN].value).toBe('auto.aws.aws_sdk');
expect(converseSpan!.attributes[SENTRY_OP].value).toBe('gen_ai.chat');
expect(converseSpan!.attributes[GEN_AI_PROVIDER_NAME].value).toBe('aws.bedrock');
expect(converseSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('chat');
expect(converseSpan!.attributes[GEN_AI_REQUEST_MODEL].value).toBe(MODEL_ID);
expect(converseSpan!.attributes[GEN_AI_REQUEST_MAX_TOKENS].value).toBe(100);
expect(converseSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE].value).toBe(0.5);
expect(converseSpan!.attributes[GEN_AI_REQUEST_TOP_P].value).toBe(0.9);
expect(converseSpan!.attributes[GEN_AI_USAGE_INPUT_TOKENS].value).toBe(12);
expect(converseSpan!.attributes[GEN_AI_USAGE_OUTPUT_TOKENS].value).toBe(8);
expect(converseSpan!.attributes[GEN_AI_RESPONSE_FINISH_REASONS].value).toEqual(['end_turn']);

// InvokeModel (non-streaming, anthropic.claude request/response body)
const invokeModelSpan = container.items.find(span => span.name === `generate_content ${MODEL_ID}`);
expect(invokeModelSpan).toBeDefined();
expect(invokeModelSpan!.status).toBe('ok');
expect(invokeModelSpan!.attributes['sentry.origin'].value).toBe('auto.aws.aws_sdk');
expect(invokeModelSpan!.attributes['sentry.op'].value).toBe('gen_ai.generate_content');
expect(invokeModelSpan!.attributes['gen_ai.provider.name'].value).toBe('aws.bedrock');
expect(invokeModelSpan!.attributes['gen_ai.operation.name'].value).toBe('generate_content');
expect(invokeModelSpan!.attributes['gen_ai.request.model'].value).toBe(MODEL_ID);
expect(invokeModelSpan!.attributes['gen_ai.request.max_tokens'].value).toBe(100);
expect(invokeModelSpan!.attributes['gen_ai.request.temperature'].value).toBe(0.5);
expect(invokeModelSpan!.attributes['gen_ai.request.top_p'].value).toBe(0.9);
expect(invokeModelSpan!.attributes['gen_ai.usage.input_tokens'].value).toBe(15);
expect(invokeModelSpan!.attributes['gen_ai.usage.output_tokens'].value).toBe(9);
expect(invokeModelSpan!.attributes['gen_ai.response.finish_reasons'].value).toEqual(['end_turn']);
expect(invokeModelSpan!.attributes[SENTRY_ORIGIN].value).toBe('auto.aws.aws_sdk');
expect(invokeModelSpan!.attributes[SENTRY_OP].value).toBe('gen_ai.generate_content');
expect(invokeModelSpan!.attributes[GEN_AI_PROVIDER_NAME].value).toBe('aws.bedrock');
expect(invokeModelSpan!.attributes[GEN_AI_OPERATION_NAME].value).toBe('generate_content');
expect(invokeModelSpan!.attributes[GEN_AI_REQUEST_MODEL].value).toBe(MODEL_ID);
expect(invokeModelSpan!.attributes[GEN_AI_REQUEST_MAX_TOKENS].value).toBe(100);
expect(invokeModelSpan!.attributes[GEN_AI_REQUEST_TEMPERATURE].value).toBe(0.5);
expect(invokeModelSpan!.attributes[GEN_AI_REQUEST_TOP_P].value).toBe(0.9);
expect(invokeModelSpan!.attributes[GEN_AI_USAGE_INPUT_TOKENS].value).toBe(15);
expect(invokeModelSpan!.attributes[GEN_AI_USAGE_OUTPUT_TOKENS].value).toBe(9);
expect(invokeModelSpan!.attributes[GEN_AI_RESPONSE_FINISH_REASONS].value).toEqual(['end_turn']);
}

describe('awsIntegration - Bedrock', () => {
Expand All @@ -49,12 +63,7 @@ describe('awsIntegration - Bedrock', () => {
'instrument.mjs',
(createTestRunner, test) => {
test('auto-instruments Bedrock Converse and InvokeModel', { timeout: 90_000 }, async () => {
await createTestRunner()
.ignore('event')
.expect({ transaction: transaction => expect(transaction.transaction).toBe('Test Transaction') })
.expect({ span: assertBedrockSpans })
.start()
.completed();
await createTestRunner().ignore('event').expect({ span: assertBedrockSpans }).start().completed();
});
},
{ additionalDependencies: { '@aws-sdk/client-bedrock-runtime': '^3.1046.0' } },
Expand Down
Loading