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
13 changes: 11 additions & 2 deletions packages/core/src/utils/prepareEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,17 @@ export function applyClientOptions(event: Event, options: ClientOptions): void {
}

const request = event.request;
if (request?.url) {
request.url = maxValueLength ? truncate(request.url, maxValueLength) : request.url;
if (request?.url && maxValueLength) {
request.url = truncate(request.url, maxValueLength);
}

if (maxValueLength) {
event.exception?.values?.forEach(exception => {
if (exception.value) {
// Truncates error messages
exception.value = truncate(exception.value, maxValueLength);
}
});
}
}

Expand Down
32 changes: 30 additions & 2 deletions packages/core/test/lib/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import type { ErrorEvent, Event, TransactionEvent } from '../../src/types-hoist/
import type { SpanJSON } from '../../src/types-hoist/span';
import * as debugLoggerModule from '../../src/utils/debug-logger';
import * as miscModule from '../../src/utils/misc';
import * as stringModule from '../../src/utils/string';
import * as timeModule from '../../src/utils/time';
import { getDefaultTestClientOptions, TestClient } from '../mocks/client';
import { AdHocIntegration, AsyncTestIntegration, TestIntegration } from '../mocks/integration';
Expand All @@ -37,7 +36,6 @@ const clientProcess = vi.spyOn(TestClient.prototype as any, '_process');

vi.spyOn(miscModule, 'uuid4').mockImplementation(() => '12312012123120121231201212312012');
vi.spyOn(debugLoggerModule, 'consoleSandbox').mockImplementation(cb => cb());
vi.spyOn(stringModule, 'truncate').mockImplementation(str => str);
vi.spyOn(timeModule, 'dateTimestampInSeconds').mockImplementation(() => 2020);

describe('Client', () => {
Expand Down Expand Up @@ -263,6 +261,36 @@ describe('Client', () => {
);
});

test('does not truncate exception values by default', () => {
const exceptionMessageLength = 10_000;
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
const client = new TestClient(options);

client.captureException(new Error('a'.repeat(exceptionMessageLength)));
expect(TestClient.instance!.event).toEqual(
expect.objectContaining({
exception: {
values: [{ type: 'Error', value: 'a'.repeat(exceptionMessageLength) }],
},
}),
);
});

test('truncates exception values according to `maxValueLength` option', () => {
const maxValueLength = 10;
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN, maxValueLength });
const client = new TestClient(options);

client.captureException(new Error('a'.repeat(50)));
expect(TestClient.instance!.event).toEqual(
expect.objectContaining({
exception: {
values: [{ type: 'Error', value: `${'a'.repeat(maxValueLength)}...` }],
},
}),
);
});

test('sets the correct lastEventId', () => {
const options = getDefaultTestClientOptions({ dsn: PUBLIC_DSN });
const client = new TestClient(options);
Expand Down