Skip to content

Commit 5f5d49e

Browse files
committed
Flip enableTruncation default to false
1 parent 76d835c commit 5f5d49e

17 files changed

Lines changed: 101 additions & 37 deletions

dev-packages/node-integration-tests/suites/tracing/anthropic/scenario-media-truncation.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async function run() {
4646
apiKey: 'mock-api-key',
4747
});
4848

49-
const client = instrumentAnthropicAiClient(mockClient);
49+
const client = instrumentAnthropicAiClient(mockClient, { enableTruncation: true });
5050

5151
// Send the image showing the number 3
5252
// Put the image in the last message so it doesn't get dropped

dev-packages/node-integration-tests/suites/tracing/anthropic/scenario-message-truncation.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ async function run() {
4646
apiKey: 'mock-api-key',
4747
});
4848

49-
const client = instrumentAnthropicAiClient(mockClient);
49+
const client = instrumentAnthropicAiClient(mockClient, { enableTruncation: true });
5050

5151
// Test 1: Given an array of messages only the last message should be kept
5252
// The last message should be truncated to fit within the 20KB limit

dev-packages/node-integration-tests/suites/tracing/anthropic/scenario-system-instructions.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,18 @@ async function run() {
4343
baseURL: `http://localhost:${server.address().port}/anthropic`,
4444
});
4545

46+
// Multiple long messages verify default-off truncation: with `enableTruncation` unset,
47+
// neither byte-truncation nor message popping should occur. The full array is preserved as-is.
48+
const longContent = 'A'.repeat(50_000);
4649
await client.messages.create({
4750
model: 'claude-3-5-sonnet-20241022',
4851
max_tokens: 1024,
4952
system: 'You are a helpful assistant',
50-
messages: [{ role: 'user', content: 'Hello' }],
53+
messages: [
54+
{ role: 'user', content: longContent },
55+
{ role: 'assistant', content: 'Some reply' },
56+
{ role: 'user', content: 'Follow-up question' },
57+
],
5158
});
5259
});
5360

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,13 @@ describe('Anthropic integration', () => {
671671
'scenario-system-instructions.mjs',
672672
'instrument-with-pii.mjs',
673673
(createRunner, test) => {
674-
test('extracts system instructions from messages', async () => {
674+
test('extracts system instructions and preserves full multi-message input by default (enableTruncation unset)', async () => {
675675
const expectedInstructions = JSON.stringify([{ type: 'text', content: 'You are a helpful assistant' }]);
676+
const expectedMessages = JSON.stringify([
677+
{ role: 'user', content: 'A'.repeat(50_000) },
678+
{ role: 'assistant', content: 'Some reply' },
679+
{ role: 'user', content: 'Follow-up question' },
680+
]);
676681
await createRunner()
677682
.ignore('event')
678683
.expect({
@@ -687,6 +692,9 @@ describe('Anthropic integration', () => {
687692

688693
// [0] messages.create — system instructions extracted into dedicated attribute
689694
expect(firstSpan!.attributes[GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE].value).toBe(expectedInstructions);
695+
// Default-off: no byte-truncation of the 50KB message and no message popping to keep-last-only.
696+
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value).toBe(expectedMessages);
697+
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE].value).toBe(3);
690698
},
691699
})
692700
.start()

dev-packages/node-integration-tests/suites/tracing/google-genai/scenario-message-truncation.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function run() {
4141
apiKey: 'mock-api-key',
4242
});
4343

44-
const client = instrumentGoogleGenAIClient(mockClient);
44+
const client = instrumentGoogleGenAIClient(mockClient, { enableTruncation: true });
4545

4646
// Test 1: Given an array of messages only the last message should be kept
4747
// The last message should be truncated to fit within the 20KB limit

dev-packages/node-integration-tests/suites/tracing/google-genai/scenario-system-instructions.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,19 @@ async function run() {
3737
const mockClient = new MockGoogleGenAI({ apiKey: 'mock-api-key' });
3838
const client = instrumentGoogleGenAIClient(mockClient);
3939

40+
// Multiple long messages verify default-off truncation: with `enableTruncation` unset,
41+
// neither byte-truncation nor message popping should occur. The full array is preserved as-is.
42+
const longContent = 'A'.repeat(50_000);
4043
await client.models.generateContent({
4144
model: 'gemini-1.5-flash',
4245
config: {
4346
systemInstruction: 'You are a helpful assistant',
4447
},
45-
contents: [{ role: 'user', parts: [{ text: 'Hello' }] }],
48+
contents: [
49+
{ role: 'user', parts: [{ text: longContent }] },
50+
{ role: 'model', parts: [{ text: 'Some reply' }] },
51+
{ role: 'user', parts: [{ text: 'Follow-up question' }] },
52+
],
4653
});
4754
});
4855
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,12 @@ describe('Google GenAI integration', () => {
344344
'scenario-system-instructions.mjs',
345345
'instrument-with-pii.mjs',
346346
(createRunner, test) => {
347-
test('extracts system instructions from messages', async () => {
347+
test('extracts system instructions and preserves full multi-message input by default (enableTruncation unset)', async () => {
348+
const expectedMessages = JSON.stringify([
349+
{ role: 'user', parts: [{ text: 'A'.repeat(50_000) }] },
350+
{ role: 'model', parts: [{ text: 'Some reply' }] },
351+
{ role: 'user', parts: [{ text: 'Follow-up question' }] },
352+
]);
348353
await createRunner()
349354
.ignore('event')
350355
.expect({ transaction: { transaction: 'main' } })
@@ -358,6 +363,9 @@ describe('Google GenAI integration', () => {
358363
expect(firstSpan!.attributes[GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE].value).toBe(
359364
JSON.stringify([{ type: 'text', content: 'You are a helpful assistant' }]),
360365
);
366+
// Default-off: no byte-truncation of the 50KB message and no message popping to keep-last-only.
367+
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ATTRIBUTE].value).toBe(expectedMessages);
368+
expect(firstSpan!.attributes[GEN_AI_INPUT_MESSAGES_ORIGINAL_LENGTH_ATTRIBUTE].value).toBe(3);
361369
},
362370
})
363371
.start()

dev-packages/node-integration-tests/suites/tracing/langchain/instrument-with-pii.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Sentry.init({
77
tracesSampleRate: 1.0,
88
sendDefaultPii: true,
99
transport: loggingTransport,
10+
integrations: [
11+
Sentry.langChainIntegration({
12+
enableTruncation: true,
13+
}),
14+
],
1015
beforeSendTransaction: event => {
1116
// Filter out mock express server transactions
1217
if (event.transaction.includes('/v1/messages') || event.transaction.includes('/v1/embeddings')) {

dev-packages/node-integration-tests/suites/tracing/langchain/v1/instrument-with-pii.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Sentry.init({
77
tracesSampleRate: 1.0,
88
sendDefaultPii: true,
99
transport: loggingTransport,
10+
integrations: [
11+
Sentry.langChainIntegration({
12+
enableTruncation: true,
13+
}),
14+
],
1015
beforeSendTransaction: event => {
1116
// Filter out mock express server transactions
1217
if (event.transaction.includes('/v1/messages') || event.transaction.includes('/v1/chat/completions')) {

dev-packages/node-integration-tests/suites/tracing/langgraph/scenario-system-instructions.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ async function run() {
2929
.addEdge('agent', END)
3030
.compile({ name: 'test-agent' });
3131

32+
// Multiple long messages verify default-off truncation: with `enableTruncation` unset,
33+
// neither byte-truncation nor message popping should occur. The full array is preserved as-is.
34+
const longContent = 'A'.repeat(50_000);
3235
await graph.invoke({
3336
messages: [
3437
{ role: 'system', content: 'You are a helpful assistant' },
35-
{ role: 'user', content: 'Hello' },
38+
{ role: 'user', content: longContent },
39+
{ role: 'assistant', content: 'Some reply' },
40+
{ role: 'user', content: 'Follow-up question' },
3641
],
3742
});
3843
});

0 commit comments

Comments
 (0)