Skip to content

Commit 2d760ba

Browse files
authored
feat(core): Remove default value of maxValueLength: 250 (#18043)
The SDK should only truncate when really necessary on the client. Therefore, the default value of 250 is removed. Part of #17389
1 parent 98de756 commit 2d760ba

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

packages/core/src/integrations/extraerrordata.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const _extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {
3434
return {
3535
name: INTEGRATION_NAME,
3636
processEvent(event, hint, client) {
37-
const { maxValueLength = 250 } = client.getOptions();
37+
const { maxValueLength } = client.getOptions();
3838
return _enhanceEventWithErrorData(event, hint, depth, captureErrorCause, maxValueLength);
3939
},
4040
};
@@ -47,7 +47,7 @@ function _enhanceEventWithErrorData(
4747
hint: EventHint = {},
4848
depth: number,
4949
captureErrorCause: boolean,
50-
maxValueLength: number,
50+
maxValueLength: number | undefined,
5151
): Event {
5252
if (!hint.originalException || !isError(hint.originalException)) {
5353
return event;
@@ -85,7 +85,7 @@ function _enhanceEventWithErrorData(
8585
function _extractErrorData(
8686
error: ExtendedError,
8787
captureErrorCause: boolean,
88-
maxValueLength: number,
88+
maxValueLength: number | undefined,
8989
): Record<string, unknown> | null {
9090
// We are trying to enhance already existing event, so no harm done if it won't succeed
9191
try {
@@ -109,7 +109,12 @@ function _extractErrorData(
109109
continue;
110110
}
111111
const value = error[key];
112-
extraErrorInfo[key] = isError(value) || typeof value === 'string' ? truncate(`${value}`, maxValueLength) : value;
112+
extraErrorInfo[key] =
113+
isError(value) || typeof value === 'string'
114+
? maxValueLength
115+
? truncate(`${value}`, maxValueLength)
116+
: `${value}`
117+
: value;
113118
}
114119

115120
// Error.cause is a standard property that is non enumerable, we therefore need to access it separately.

packages/core/src/types-hoist/options.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
184184

185185
/**
186186
* Maximum number of chars a single value can have before it will be truncated.
187-
*
188-
* @default 250
189187
*/
190188
maxValueLength?: number;
191189

packages/core/src/utils/prepareEvent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function prepareEvent(
132132
* @param event event instance to be enhanced
133133
*/
134134
export function applyClientOptions(event: Event, options: ClientOptions): void {
135-
const { environment, release, dist, maxValueLength = 250 } = options;
135+
const { environment, release, dist, maxValueLength } = options;
136136

137137
// empty strings do not make sense for environment, release, and dist
138138
// so we handle them the same as if they were not provided
@@ -148,7 +148,7 @@ export function applyClientOptions(event: Event, options: ClientOptions): void {
148148

149149
const request = event.request;
150150
if (request?.url) {
151-
request.url = truncate(request.url, maxValueLength);
151+
request.url = maxValueLength ? truncate(request.url, maxValueLength) : request.url;
152152
}
153153
}
154154

packages/core/test/lib/integrations/extraerrordata.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,27 @@ describe('ExtraErrorData()', () => {
5555
});
5656
});
5757

58+
it('should not truncate extra data without maxValueLength', () => {
59+
const error = new TypeError('foo') as ExtendedError;
60+
error.baz = 42;
61+
error.foo = 'a'.repeat(300);
62+
63+
const enhancedEvent = extraErrorData.processEvent?.(
64+
event,
65+
{
66+
originalException: error,
67+
},
68+
new TestClient(getDefaultTestClientOptions()),
69+
) as Event;
70+
71+
expect(enhancedEvent.contexts).toEqual({
72+
TypeError: {
73+
baz: 42,
74+
foo: `${'a'.repeat(300)}`,
75+
},
76+
});
77+
});
78+
5879
it('should extract error data from the error cause with the same policy', () => {
5980
const error = new TypeError('foo') as ExtendedError;
6081
error.cause = new SyntaxError('bar') as ExtendedError;

0 commit comments

Comments
 (0)