diff --git a/packages/node/src/eventbuilder.ts b/packages/node/src/eventbuilder.ts index eead089793a0..c6fdeb0598e2 100644 --- a/packages/node/src/eventbuilder.ts +++ b/packages/node/src/eventbuilder.ts @@ -62,8 +62,11 @@ export function eventFromUnknownInput(stackParser: StackParser, exception: unkno // which is much better than creating new group when any key/value change const message = `Non-Error exception captured with keys: ${extractExceptionKeysForMessage(exception)}`; - getCurrentHub().configureScope(scope => { - scope.setExtra('__serialized__', normalizeToSize(exception)); + const hub = getCurrentHub(); + const client = hub.getClient(); + const normalizeDepth = client && client.getOptions().normalizeDepth; + hub.configureScope(scope => { + scope.setExtra('__serialized__', normalizeToSize(exception, normalizeDepth)); }); ex = (hint && hint.syntheticException) || new Error(message); diff --git a/packages/node/test/eventbuilders.test.ts b/packages/node/test/eventbuilders.test.ts new file mode 100644 index 000000000000..f92ec303bb3c --- /dev/null +++ b/packages/node/test/eventbuilders.test.ts @@ -0,0 +1,76 @@ +import { Client } from '@sentry/types'; + +import { defaultStackParser, Scope } from '../src'; +import { eventFromUnknownInput } from '../src/eventbuilder'; + +const testScope = new Scope(); + +jest.mock('@sentry/hub', () => { + const original = jest.requireActual('@sentry/hub'); + return { + ...original, + getCurrentHub(): { + getClient(): Client; + getScope(): Scope; + configureScope(scopeFunction: (scope: Scope) => void): void; + } { + return { + getClient(): any { + return { + getOptions(): any { + return { normalizeDepth: 6 }; + }, + }; + }, + getScope(): Scope { + return new Scope(); + }, + configureScope(scopeFunction: (scope: Scope) => void): void { + scopeFunction(testScope); + }, + }; + }, + }; +}); + +afterEach(() => { + jest.resetAllMocks(); +}); + +describe('eventFromUnknownInput', () => { + test('uses normalizeDepth from init options', () => { + const deepObject = { + a: { + b: { + c: { + d: { + e: { + f: { + g: 'foo', + }, + }, + }, + }, + }, + }, + }; + + eventFromUnknownInput(defaultStackParser, deepObject); + + const serializedObject = (testScope as any)._extra.__serialized__; + expect(serializedObject).toBeDefined(); + expect(serializedObject).toEqual({ + a: { + b: { + c: { + d: { + e: { + f: '[Object]', + }, + }, + }, + }, + }, + }); + }); +});