Skip to content

Commit a6d2b06

Browse files
lforstonurtemizkan
authored andcommitted
feat: Don't truncate error messages (#15818)
Ref https://github.com/getsentry/projects/issues/837 for for not truncating error messages and letting relay do that. Kinda undoes #8593 Should be merged after #15819 because otherwise, we keep humongous strings in memory.
1 parent f73c158 commit a6d2b06

File tree

9 files changed

+40
-155
lines changed

9 files changed

+40
-155
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const wat = new Error(`This is a very long message that should be truncated and will be,
2-
this is a very long message that should be truncated and will be,
3-
this is a very long message that should be truncated and will be,
4-
this is a very long message that should be truncated and will be,
5-
this is a very long message that should be truncated and will be`);
1+
const wat = new Error(`This is a very long message that should not be truncated and won't be,
2+
this is a very long message that should not be truncated and won't be,
3+
this is a very long message that should not be truncated and won't be,
4+
this is a very long message that should not be truncated and won't be,
5+
this is a very long message that should not be truncated and won't be`);
66

7-
wat.cause = new Error(`This is a very long message that should be truncated and hopefully will be,
8-
this is a very long message that should be truncated and hopefully will be,
9-
this is a very long message that should be truncated and hopefully will be,
10-
this is a very long message that should be truncated and hopefully will be,
11-
this is a very long message that should be truncated and hopefully will be,`);
7+
wat.cause = new Error(`This is a very long message that should not be truncated and hopefully won't be,
8+
this is a very long message that should not be truncated and hopefully won't be,
9+
this is a very long message that should not be truncated and hopefully won't be,
10+
this is a very long message that should not be truncated and hopefully won't be,
11+
this is a very long message that should not be truncated and hopefully won't be`);
1212

1313
Sentry.captureException(wat);

dev-packages/browser-integration-tests/suites/public-api/captureException/linkedErrors/test.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ sentryTest('should capture a linked error with messages', async ({ getLocalTestU
1212
expect(eventData.exception?.values).toHaveLength(2);
1313
expect(eventData.exception?.values?.[0]).toMatchObject({
1414
type: 'Error',
15-
value: `This is a very long message that should be truncated and hopefully will be,
16-
this is a very long message that should be truncated and hopefully will be,
17-
this is a very long message that should be truncated and hopefully will be,
18-
this is a very long me...`,
15+
value: `This is a very long message that should not be truncated and hopefully won't be,
16+
this is a very long message that should not be truncated and hopefully won't be,
17+
this is a very long message that should not be truncated and hopefully won't be,
18+
this is a very long message that should not be truncated and hopefully won't be,
19+
this is a very long message that should not be truncated and hopefully won't be`,
1920
mechanism: {
2021
type: 'chained',
2122
handled: true,
@@ -26,10 +27,11 @@ this is a very long me...`,
2627
});
2728
expect(eventData.exception?.values?.[1]).toMatchObject({
2829
type: 'Error',
29-
value: `This is a very long message that should be truncated and will be,
30-
this is a very long message that should be truncated and will be,
31-
this is a very long message that should be truncated and will be,
32-
this is a very long message that should be truncated...`,
30+
value: `This is a very long message that should not be truncated and won't be,
31+
this is a very long message that should not be truncated and won't be,
32+
this is a very long message that should not be truncated and won't be,
33+
this is a very long message that should not be truncated and won't be,
34+
this is a very long message that should not be truncated and won't be`,
3335
mechanism: {
3436
type: 'generic',
3537
handled: true,

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onUnhandledRejection/thrown-string-large/subject.js

-9
This file was deleted.

dev-packages/browser-integration-tests/suites/public-api/instrumentation/onUnhandledRejection/thrown-string-large/test.ts

-22
This file was deleted.

packages/browser/src/integrations/linkederrors.ts

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const _linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {
2525
// This differs from the LinkedErrors integration in core by using a different exceptionFromError function
2626
exceptionFromError,
2727
options.stackParser,
28-
options.maxValueLength,
2928
key,
3029
limit,
3130
event,

packages/core/src/integrations/linkederrors.ts

+1-9
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,7 @@ const _linkedErrorsIntegration = ((options: LinkedErrorsOptions = {}) => {
2222
preprocessEvent(event, hint, client) {
2323
const options = client.getOptions();
2424

25-
applyAggregateErrorsToEvent(
26-
exceptionFromError,
27-
options.stackParser,
28-
options.maxValueLength,
29-
key,
30-
limit,
31-
event,
32-
hint,
33-
);
25+
applyAggregateErrorsToEvent(exceptionFromError, options.stackParser, key, limit, event, hint);
3426
},
3527
};
3628
}) satisfies IntegrationFn;

packages/core/src/utils-hoist/aggregate-errors.ts

+9-28
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import type { Event, EventHint, Exception, ExtendedError, StackParser } from '../types-hoist';
22

33
import { isInstanceOf } from './is';
4-
import { truncate } from './string';
54

65
/**
76
* Creates exceptions inside `event.exception.values` for errors that are nested on properties based on the `key` parameter.
87
*/
98
export function applyAggregateErrorsToEvent(
109
exceptionFromErrorImplementation: (stackParser: StackParser, ex: Error) => Exception,
1110
parser: StackParser,
12-
maxValueLimit: number = 250,
1311
key: string,
1412
limit: number,
1513
event: Event,
@@ -25,18 +23,15 @@ export function applyAggregateErrorsToEvent(
2523

2624
// We only create exception grouping if there is an exception in the event.
2725
if (originalException) {
28-
event.exception.values = truncateAggregateExceptions(
29-
aggregateExceptionsFromError(
30-
exceptionFromErrorImplementation,
31-
parser,
32-
limit,
33-
hint.originalException as ExtendedError,
34-
key,
35-
event.exception.values,
36-
originalException,
37-
0,
38-
),
39-
maxValueLimit,
26+
event.exception.values = aggregateExceptionsFromError(
27+
exceptionFromErrorImplementation,
28+
parser,
29+
limit,
30+
hint.originalException as ExtendedError,
31+
key,
32+
event.exception.values,
33+
originalException,
34+
0,
4035
);
4136
}
4237
}
@@ -129,17 +124,3 @@ function applyExceptionGroupFieldsForChildException(
129124
parent_id: parentId,
130125
};
131126
}
132-
133-
/**
134-
* Truncate the message (exception.value) of all exceptions in the event.
135-
* Because this event processor is ran after `applyClientOptions`,
136-
* we need to truncate the message of the added exceptions here.
137-
*/
138-
function truncateAggregateExceptions(exceptions: Exception[], maxValueLength: number): Exception[] {
139-
return exceptions.map(exception => {
140-
if (exception.value) {
141-
exception.value = truncate(exception.value, maxValueLength);
142-
}
143-
return exception;
144-
});
145-
}

packages/core/src/utils/prepareEvent.ts

-9
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,6 @@ export function applyClientOptions(event: Event, options: ClientOptions): void {
144144
event.dist = dist;
145145
}
146146

147-
if (event.message) {
148-
event.message = truncate(event.message, maxValueLength);
149-
}
150-
151-
const exception = event.exception?.values?.[0];
152-
if (exception?.value) {
153-
exception.value = truncate(exception.value, maxValueLength);
154-
}
155-
156147
const request = event.request;
157148
if (request?.url) {
158149
request.url = truncate(request.url, maxValueLength);

packages/core/test/utils-hoist/aggregate-errors.test.ts

+10-59
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('applyAggregateErrorsToEvent()', () => {
2121
test('should not do anything if event does not contain an exception', () => {
2222
const event: Event = { exception: undefined };
2323
const eventHint: EventHint = { originalException: new Error() };
24-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, 'cause', 100, event, eventHint);
24+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint);
2525

2626
// no changes
2727
expect(event).toStrictEqual({ exception: undefined });
@@ -30,15 +30,15 @@ describe('applyAggregateErrorsToEvent()', () => {
3030
test('should not do anything if event does not contain exception values', () => {
3131
const event: Event = { exception: { values: undefined } };
3232
const eventHint: EventHint = { originalException: new Error() };
33-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, 'cause', 100, event, eventHint);
33+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint);
3434

3535
// no changes
3636
expect(event).toStrictEqual({ exception: { values: undefined } });
3737
});
3838

3939
test('should not do anything if event does not contain an event hint', () => {
4040
const event: Event = { exception: { values: [] } };
41-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, 'cause', 100, event, undefined);
41+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, undefined);
4242

4343
// no changes
4444
expect(event).toStrictEqual({ exception: { values: [] } });
@@ -47,7 +47,7 @@ describe('applyAggregateErrorsToEvent()', () => {
4747
test('should not do anything if the event hint does not contain an original exception', () => {
4848
const event: Event = { exception: { values: [] } };
4949
const eventHint: EventHint = { originalException: undefined };
50-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, 'cause', 100, event, eventHint);
50+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint);
5151

5252
// no changes
5353
expect(event).toStrictEqual({ exception: { values: [] } });
@@ -62,7 +62,7 @@ describe('applyAggregateErrorsToEvent()', () => {
6262
const event: Event = { exception: { values: [exceptionFromError(stackParser, originalException)] } };
6363
const eventHint: EventHint = { originalException };
6464

65-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, key, 100, event, eventHint);
65+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, key, 100, event, eventHint);
6666
expect(event).toStrictEqual({
6767
exception: {
6868
values: [
@@ -108,7 +108,7 @@ describe('applyAggregateErrorsToEvent()', () => {
108108
const event: Event = { exception: { values: [exceptionFromError(stackParser, originalException)] } };
109109
const eventHint: EventHint = { originalException };
110110

111-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, 'cause', 100, event, eventHint);
111+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint);
112112

113113
// no changes
114114
expect(event).toStrictEqual({ exception: { values: [exceptionFromError(stackParser, originalException)] } });
@@ -127,7 +127,7 @@ describe('applyAggregateErrorsToEvent()', () => {
127127
}
128128

129129
const eventHint: EventHint = { originalException };
130-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, key, 5, event, eventHint);
130+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, key, 5, event, eventHint);
131131

132132
// 6 -> one for original exception + 5 linked
133133
expect(event.exception?.values).toHaveLength(5 + 1);
@@ -153,7 +153,7 @@ describe('applyAggregateErrorsToEvent()', () => {
153153
const event: Event = { exception: { values: [exceptionFromError(stackParser, fakeAggregateError)] } };
154154
const eventHint: EventHint = { originalException: fakeAggregateError };
155155

156-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, 'cause', 100, event, eventHint);
156+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint);
157157
expect(event.exception?.values?.[event.exception.values.length - 1]?.mechanism?.type).toBe('instrument');
158158
});
159159

@@ -170,7 +170,7 @@ describe('applyAggregateErrorsToEvent()', () => {
170170
const event: Event = { exception: { values: [exceptionFromError(stackParser, fakeAggregateError1)] } };
171171
const eventHint: EventHint = { originalException: fakeAggregateError1 };
172172

173-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, 'cause', 100, event, eventHint);
173+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, 'cause', 100, event, eventHint);
174174
expect(event).toStrictEqual({
175175
exception: {
176176
values: [
@@ -254,7 +254,7 @@ describe('applyAggregateErrorsToEvent()', () => {
254254
const event: Event = { exception: { values: [exceptionFromError(stackParser, originalException)] } };
255255
const eventHint: EventHint = { originalException };
256256

257-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, undefined, key, 100, event, eventHint);
257+
applyAggregateErrorsToEvent(exceptionFromError, stackParser, key, 100, event, eventHint);
258258
expect(event).toStrictEqual({
259259
exception: {
260260
values: [
@@ -293,53 +293,4 @@ describe('applyAggregateErrorsToEvent()', () => {
293293
},
294294
});
295295
});
296-
297-
test('should truncate the exception values if they exceed the `maxValueLength` option', () => {
298-
const originalException: ExtendedError = new Error('Root Error with long message');
299-
originalException.cause = new Error('Nested Error 1 with longer message');
300-
originalException.cause.cause = new Error('Nested Error 2 with longer message with longer message');
301-
302-
const event: Event = { exception: { values: [exceptionFromError(stackParser, originalException)] } };
303-
const eventHint: EventHint = { originalException };
304-
305-
const maxValueLength = 15;
306-
applyAggregateErrorsToEvent(exceptionFromError, stackParser, maxValueLength, 'cause', 10, event, eventHint);
307-
expect(event).toStrictEqual({
308-
exception: {
309-
values: [
310-
{
311-
type: 'Error',
312-
value: 'Nested Error 2 ...',
313-
mechanism: {
314-
exception_id: 2,
315-
handled: true,
316-
parent_id: 1,
317-
source: 'cause',
318-
type: 'chained',
319-
},
320-
},
321-
{
322-
type: 'Error',
323-
value: 'Nested Error 1 ...',
324-
mechanism: {
325-
exception_id: 1,
326-
handled: true,
327-
parent_id: 0,
328-
source: 'cause',
329-
type: 'chained',
330-
},
331-
},
332-
{
333-
type: 'Error',
334-
value: 'Root Error with...',
335-
mechanism: {
336-
exception_id: 0,
337-
handled: true,
338-
type: 'instrument',
339-
},
340-
},
341-
],
342-
},
343-
});
344-
});
345296
});

0 commit comments

Comments
 (0)