Skip to content

Commit a9d34ef

Browse files
author
Luca Forstner
authored
fix(browser): Use normalizeDepth option when creating an event from a plain object (#5705)
1 parent 732c42d commit a9d34ef

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

packages/browser/src/eventbuilder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getCurrentHub } from '@sentry/core';
12
import { Event, EventHint, Exception, Severity, SeverityLevel, StackFrame, StackParser } from '@sentry/types';
23
import {
34
addExceptionMechanism,
@@ -45,6 +46,10 @@ export function eventFromPlainObject(
4546
syntheticException?: Error,
4647
isUnhandledRejection?: boolean,
4748
): Event {
49+
const hub = getCurrentHub();
50+
const client = hub.getClient();
51+
const normalizeDepth = client && client.getOptions().normalizeDepth;
52+
4853
const event: Event = {
4954
exception: {
5055
values: [
@@ -57,7 +62,7 @@ export function eventFromPlainObject(
5762
],
5863
},
5964
extra: {
60-
__serialized__: normalizeToSize(exception),
65+
__serialized__: normalizeToSize(exception, normalizeDepth),
6166
},
6267
};
6368

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Client } from '@sentry/types';
2+
3+
import { defaultStackParser } from '../../src';
4+
import { eventFromPlainObject } from '../../src/eventbuilder';
5+
6+
jest.mock('@sentry/core', () => {
7+
const original = jest.requireActual('@sentry/core');
8+
return {
9+
...original,
10+
getCurrentHub(): {
11+
getClient(): Client;
12+
} {
13+
return {
14+
getClient(): any {
15+
return {
16+
getOptions(): any {
17+
return { normalizeDepth: 6 };
18+
},
19+
};
20+
},
21+
};
22+
},
23+
};
24+
});
25+
26+
afterEach(() => {
27+
jest.resetAllMocks();
28+
});
29+
30+
describe('eventFromPlainObject', () => {
31+
it('should use normalizeDepth from init options', () => {
32+
const deepObject = {
33+
a: {
34+
b: {
35+
c: {
36+
d: {
37+
e: {
38+
f: {
39+
g: 'foo',
40+
},
41+
},
42+
},
43+
},
44+
},
45+
},
46+
};
47+
48+
const event = eventFromPlainObject(defaultStackParser, deepObject);
49+
50+
expect(event?.extra?.__serialized__).toEqual({
51+
a: {
52+
b: {
53+
c: {
54+
d: {
55+
e: {
56+
f: '[Object]',
57+
},
58+
},
59+
},
60+
},
61+
},
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)