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: 9 additions & 4 deletions packages/core/src/integrations/extraerrordata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const _extraErrorDataIntegration = ((options: Partial<ExtraErrorDataOptions> = {
return {
name: INTEGRATION_NAME,
processEvent(event, hint, client) {
const { maxValueLength = 250 } = client.getOptions();
const { maxValueLength } = client.getOptions();
return _enhanceEventWithErrorData(event, hint, depth, captureErrorCause, maxValueLength);
},
};
Expand All @@ -47,7 +47,7 @@ function _enhanceEventWithErrorData(
hint: EventHint = {},
depth: number,
captureErrorCause: boolean,
maxValueLength: number,
maxValueLength: number | undefined,
): Event {
if (!hint.originalException || !isError(hint.originalException)) {
return event;
Expand Down Expand Up @@ -85,7 +85,7 @@ function _enhanceEventWithErrorData(
function _extractErrorData(
error: ExtendedError,
captureErrorCause: boolean,
maxValueLength: number,
maxValueLength: number | undefined,
): Record<string, unknown> | null {
// We are trying to enhance already existing event, so no harm done if it won't succeed
try {
Expand All @@ -109,7 +109,12 @@ function _extractErrorData(
continue;
}
const value = error[key];
extraErrorInfo[key] = isError(value) || typeof value === 'string' ? truncate(`${value}`, maxValueLength) : value;
extraErrorInfo[key] =
isError(value) || typeof value === 'string'
? maxValueLength
? truncate(`${value}`, maxValueLength)
: `${value}`
: value;
}

// Error.cause is a standard property that is non enumerable, we therefore need to access it separately.
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/types-hoist/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp

/**
* Maximum number of chars a single value can have before it will be truncated.
*
* @default 250
*/
maxValueLength?: number;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/prepareEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function prepareEvent(
* @param event event instance to be enhanced
*/
export function applyClientOptions(event: Event, options: ClientOptions): void {
const { environment, release, dist, maxValueLength = 250 } = options;
const { environment, release, dist, maxValueLength } = options;

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

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

Expand Down
21 changes: 21 additions & 0 deletions packages/core/test/lib/integrations/extraerrordata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@ describe('ExtraErrorData()', () => {
});
});

it('should not truncate extra data without maxValueLength', () => {
const error = new TypeError('foo') as ExtendedError;
error.baz = 42;
error.foo = 'a'.repeat(300);

const enhancedEvent = extraErrorData.processEvent?.(
event,
{
originalException: error,
},
new TestClient(getDefaultTestClientOptions()),
) as Event;

expect(enhancedEvent.contexts).toEqual({
TypeError: {
baz: 42,
foo: `${'a'.repeat(300)}`,
},
});
});

it('should extract error data from the error cause with the same policy', () => {
const error = new TypeError('foo') as ExtendedError;
error.cause = new SyntaxError('bar') as ExtendedError;
Expand Down
Loading