Skip to content

Commit f4e3cf4

Browse files
authored
chore(core): Remove circular JSON debugging hacks (#5267)
In #4425 and #4574, various hacks were added to the SDK in aid of debugging #2809. Now that that issue is closed, they (and the clean-up code in tests which was there to compensate for them) can come out.
1 parent 94a07bb commit f4e3cf4

File tree

8 files changed

+9
-91
lines changed

8 files changed

+9
-91
lines changed

packages/core/src/baseclient.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,6 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
446446
}
447447

448448
return result.then(evt => {
449-
if (evt) {
450-
// TODO this is more of the hack trying to solve https://github.com/getsentry/sentry-javascript/issues/2809
451-
// it is only attached as extra data to the event if the event somehow skips being normalized
452-
evt.sdkProcessingMetadata = {
453-
...evt.sdkProcessingMetadata,
454-
normalizeDepth: `${normalize(normalizeDepth)} (${typeof normalizeDepth})`,
455-
};
456-
}
457449
if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
458450
return this._normalizeEvent(evt, normalizeDepth, normalizeMaxBreadth);
459451
}
@@ -525,8 +517,6 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
525517
});
526518
}
527519

528-
normalized.sdkProcessingMetadata = { ...normalized.sdkProcessingMetadata, baseClientNormalized: true };
529-
530520
return normalized;
531521
}
532522

packages/core/src/envelope.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,33 +73,12 @@ export function createEventEnvelope(
7373
const { transactionSampling } = event.sdkProcessingMetadata || {};
7474
const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};
7575

76-
// TODO: Below is a temporary hack in order to debug a serialization error - see
77-
// https://github.com/getsentry/sentry-javascript/issues/2809,
78-
// https://github.com/getsentry/sentry-javascript/pull/4425, and
79-
// https://github.com/getsentry/sentry-javascript/pull/4574.
80-
//
81-
// TL; DR: even though we normalize all events (which should prevent this), something is causing `JSON.stringify` to
82-
// throw a circular reference error.
83-
//
84-
// When it's time to remove it:
85-
// 1. Delete everything between here and where the request object `req` is created, EXCEPT the line deleting
86-
// `sdkProcessingMetadata`
87-
// 2. Restore the original version of the request body, which is commented out
88-
// 3. Search for either of the PR URLs above and pull out the companion hacks in the browser playwright tests and the
89-
// baseClient tests in this package
9076
enhanceEventWithSdkInfo(event, metadata && metadata.sdk);
91-
event.tags = event.tags || {};
92-
event.extra = event.extra || {};
9377

94-
// In theory, all events should be marked as having gone through normalization and so
95-
// we should never set this tag/extra data
96-
if (!(event.sdkProcessingMetadata && event.sdkProcessingMetadata.baseClientNormalized)) {
97-
event.tags.skippedNormalization = true;
98-
event.extra.normalizeDepth = event.sdkProcessingMetadata ? event.sdkProcessingMetadata.normalizeDepth : 'unset';
99-
}
100-
101-
// prevent this data from being sent to sentry
102-
// TODO: This is NOT part of the hack - DO NOT DELETE
78+
// Prevent this data (which, if it exists, was used in earlier steps in the processing pipeline) from being sent to
79+
// sentry. (Note: Our use of this property comes and goes with whatever we might be debugging, whatever hacks we may
80+
// have temporarily added, etc. Even if we don't happen to be using it at some point in the future, let's not get rid
81+
// of this `delete`, lest we miss putting it back in the next time the property is in use.)
10382
delete event.sdkProcessingMetadata;
10483

10584
const envelopeHeaders = createEventEnvelopeHeaders(event, sdkInfo, tunnel, dsn);

packages/core/test/lib/base.test.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -884,29 +884,9 @@ describe('BaseClient', () => {
884884
const normalizedTransaction = JSON.parse(JSON.stringify(transaction)); // deep-copy
885885

886886
client.captureEvent(transaction);
887-
888-
// TODO: This is to compensate for a temporary debugging hack which adds data the tests aren't anticipating to the
889-
// event. The code can be restored to its original form (the commented-out line below) once that hack is
890-
// removed. See https://github.com/getsentry/sentry-javascript/pull/4425 and
891-
// https://github.com/getsentry/sentry-javascript/pull/4574
892887
const capturedEvent = TestClient.instance!.event!;
893-
if (capturedEvent.sdkProcessingMetadata?.normalizeDepth) {
894-
if (Object.keys(capturedEvent.sdkProcessingMetadata).length === 1) {
895-
delete capturedEvent.sdkProcessingMetadata;
896-
} else {
897-
delete capturedEvent.sdkProcessingMetadata.normalizeDepth;
898-
}
899-
}
900-
if (capturedEvent.sdkProcessingMetadata?.baseClientNormalized) {
901-
if (Object.keys(capturedEvent.sdkProcessingMetadata).length === 1) {
902-
delete capturedEvent.sdkProcessingMetadata;
903-
} else {
904-
delete capturedEvent.sdkProcessingMetadata.baseClientNormalized;
905-
}
906-
}
907888

908889
expect(capturedEvent).toEqual(normalizedTransaction);
909-
// expect(TestClient.instance!.event!).toEqual(normalizedTransaction);
910890
});
911891

912892
test('calls beforeSend and uses original event without any changes', () => {

packages/core/test/mocks/client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export class TestClient extends BaseClient<TestClientOptions> {
6969

7070
public sendEvent(event: Event, hint?: EventHint): void {
7171
this.event = event;
72+
73+
// In real life, this will get deleted as part of envelope creation.
74+
delete event.sdkProcessingMetadata;
75+
7276
if (this._options.enableSend) {
7377
super.sendEvent(event, hint);
7478
return;

packages/integration-tests/suites/public-api/configureScope/clear_scope/test.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@ sentryTest('should clear previously set properties of a scope', async ({ getLoca
99

1010
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1111

12-
// TODO: This is to compensate for a temporary debugging hack which adds data the tests aren't anticipating to the
13-
// event. The code can be restored to its original form (the commented-out line below) once that hack is
14-
// removed. See https://github.com/getsentry/sentry-javascript/pull/4425 and
15-
// https://github.com/getsentry/sentry-javascript/pull/4574
16-
if (eventData.extra) {
17-
if (Object.keys(eventData.extra).length === 1) {
18-
delete eventData.extra;
19-
} else {
20-
delete eventData.extra.normalizeDepth;
21-
}
22-
}
23-
2412
expect(eventData.message).toBe('cleared_scope');
2513
expect(eventData.user).toBeUndefined();
2614
expect(eventData.tags).toBeUndefined();

packages/integration-tests/utils/helpers.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,7 @@ async function getMultipleRequests(
7070
if (urlRgx.test(request.url())) {
7171
try {
7272
reqCount -= 1;
73-
74-
// TODO: This is to compensate for a temporary debugging hack which adds data the tests aren't anticipating to
75-
// the request. The code can be restored to its original form (the commented-out line below) once that hack is
76-
// removed. See https://github.com/getsentry/sentry-javascript/pull/4425.
77-
const parsedRequest = requestParser(request);
78-
if (parsedRequest.tags) {
79-
if (
80-
Object.keys(parsedRequest.tags).length === 0 ||
81-
(Object.keys(parsedRequest.tags).length === 1 && 'skippedNormalization' in parsedRequest.tags)
82-
) {
83-
delete parsedRequest.tags;
84-
} else {
85-
delete parsedRequest.tags.skippedNormalization;
86-
}
87-
}
88-
if (parsedRequest.extra && Object.keys(parsedRequest.extra).length === 0) {
89-
delete parsedRequest.extra;
90-
}
91-
requestData.push(parsedRequest);
92-
// requestData.push(requestParser(request));
73+
requestData.push(requestParser(request));
9374

9475
if (reqCount === 0) {
9576
if (timeoutId) {

packages/node-integration-tests/suites/public-api/configureScope/clear_scope/test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ test('should clear previously set properties of a scope', async () => {
88

99
assertSentryEvent(envelope[2], {
1010
message: 'cleared_scope',
11-
tags: {},
12-
extra: {},
1311
});
1412

1513
expect((envelope[2] as Event).user).not.toBeDefined();

packages/node-integration-tests/suites/public-api/withScope/nested-scopes/test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ test('should allow nested scoping', async () => {
1111
user: {
1212
id: 'qux',
1313
},
14-
tags: {},
1514
});
1615

1716
assertSentryEvent(envelopes[3][2], {
@@ -49,6 +48,5 @@ test('should allow nested scoping', async () => {
4948
user: {
5049
id: 'qux',
5150
},
52-
tags: {},
5351
});
5452
});

0 commit comments

Comments
 (0)