Skip to content

ref(core): Log normalizeDepth when normalization is skipped #4574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
5 changes: 5 additions & 0 deletions packages/core/src/baseclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ export abstract class BaseClient<B extends Backend, O extends Options> implement
}

return result.then(evt => {
if (evt) {
// TODO this is more of the hack trying to solve https://github.com/getsentry/sentry-javascript/issues/2809
// it is only attached as extra data to the event if the event somehow skips being normalized
evt.sdkProcessingMetadata = { ...evt.sdkProcessingMetadata, normalizeDepth: normalize(normalizeDepth) };
}
if (typeof normalizeDepth === 'number' && normalizeDepth > 0) {
return this._normalizeEvent(evt, normalizeDepth);
}
Expand Down
15 changes: 10 additions & 5 deletions packages/core/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,28 @@ export function eventToSentryRequest(event: Event, api: APIDetails): SentryReque
const { method: samplingMethod, rate: sampleRate } = transactionSampling || {};

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

// In theory, all events should be marked as having gone through normalization and so
// we should never set this tag
// we should never set this tag/extra data
if (!(event.sdkProcessingMetadata && event.sdkProcessingMetadata.baseClientNormalized)) {
event.tags.skippedNormalization = true;
event.extra.normalizeDepth = event.sdkProcessingMetadata ? event.sdkProcessingMetadata.normalizeDepth : 'unset';
}

// prevent this data from being sent to sentry
Expand Down
16 changes: 15 additions & 1 deletion packages/core/test/lib/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,21 @@ describe('BaseClient', () => {

client.captureEvent(transaction);

expect(TestBackend.instance!.event!).toEqual(normalizedTransaction);
// TODO: This is to compensate for a temporary debugging hack which adds data the tests aren't anticipating to the
// event. The code can be restored to its original form (the commented-out line below) once that hack is
// removed. See https://github.com/getsentry/sentry-javascript/pull/4425 and
// https://github.com/getsentry/sentry-javascript/pull/4574
const capturedEvent = TestBackend.instance!.event!;
if (capturedEvent.sdkProcessingMetadata?.normalizeDepth) {
if (Object.keys(capturedEvent.sdkProcessingMetadata).length === 1) {
delete capturedEvent.sdkProcessingMetadata;
} else {
delete capturedEvent.sdkProcessingMetadata.normalizeDepth;
}
}

expect(capturedEvent).toEqual(normalizedTransaction);
// expect(TestBackend.instance!.event!).toEqual(normalizedTransaction);
});

test('calls beforeSend and uses original event without any changes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ sentryTest('should clear previously set properties of a scope', async ({ getLoca

const eventData = await getSentryRequest(page, url);

// TODO: This is to compensate for a temporary debugging hack which adds data the tests aren't anticipating to the
// event. The code can be restored to its original form (the commented-out line below) once that hack is
// removed. See https://github.com/getsentry/sentry-javascript/pull/4425 and
// https://github.com/getsentry/sentry-javascript/pull/4574
if (eventData.extra) {
if (Object.keys(eventData.extra).length === 1) {
delete eventData.extra;
} else {
delete eventData.extra.normalizeDepth;
}
}

expect(eventData.message).toBe('cleared_scope');
expect(eventData.user).toBeUndefined();
expect(eventData.tags).toBeUndefined();
Expand Down