Skip to content

Commit 732c42d

Browse files
authored
fix(node): Use normalizeDepth when creating an event from unknown input (#5689)
1 parent 58c067e commit 732c42d

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

packages/node/src/eventbuilder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ export function eventFromUnknownInput(stackParser: StackParser, exception: unkno
6262
// which is much better than creating new group when any key/value change
6363
const message = `Non-Error exception captured with keys: ${extractExceptionKeysForMessage(exception)}`;
6464

65-
getCurrentHub().configureScope(scope => {
66-
scope.setExtra('__serialized__', normalizeToSize(exception));
65+
const hub = getCurrentHub();
66+
const client = hub.getClient();
67+
const normalizeDepth = client && client.getOptions().normalizeDepth;
68+
hub.configureScope(scope => {
69+
scope.setExtra('__serialized__', normalizeToSize(exception, normalizeDepth));
6770
});
6871

6972
ex = (hint && hint.syntheticException) || new Error(message);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Client } from '@sentry/types';
2+
3+
import { defaultStackParser, Scope } from '../src';
4+
import { eventFromUnknownInput } from '../src/eventbuilder';
5+
6+
const testScope = new Scope();
7+
8+
jest.mock('@sentry/hub', () => {
9+
const original = jest.requireActual('@sentry/hub');
10+
return {
11+
...original,
12+
getCurrentHub(): {
13+
getClient(): Client;
14+
getScope(): Scope;
15+
configureScope(scopeFunction: (scope: Scope) => void): void;
16+
} {
17+
return {
18+
getClient(): any {
19+
return {
20+
getOptions(): any {
21+
return { normalizeDepth: 6 };
22+
},
23+
};
24+
},
25+
getScope(): Scope {
26+
return new Scope();
27+
},
28+
configureScope(scopeFunction: (scope: Scope) => void): void {
29+
scopeFunction(testScope);
30+
},
31+
};
32+
},
33+
};
34+
});
35+
36+
afterEach(() => {
37+
jest.resetAllMocks();
38+
});
39+
40+
describe('eventFromUnknownInput', () => {
41+
test('uses normalizeDepth from init options', () => {
42+
const deepObject = {
43+
a: {
44+
b: {
45+
c: {
46+
d: {
47+
e: {
48+
f: {
49+
g: 'foo',
50+
},
51+
},
52+
},
53+
},
54+
},
55+
},
56+
};
57+
58+
eventFromUnknownInput(defaultStackParser, deepObject);
59+
60+
const serializedObject = (testScope as any)._extra.__serialized__;
61+
expect(serializedObject).toBeDefined();
62+
expect(serializedObject).toEqual({
63+
a: {
64+
b: {
65+
c: {
66+
d: {
67+
e: {
68+
f: '[Object]',
69+
},
70+
},
71+
},
72+
},
73+
},
74+
});
75+
});
76+
});

0 commit comments

Comments
 (0)