Skip to content
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

ref(core): Renormalize event only after stringification errors #4425

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Jan 20, 2022

Since at least 5.19.1, we've had a bug which causes events not to be able to be serialized for transmission, because they contain circular references. In theory, this should never happen, because all events go through a normalization process which removes circular references. Nonetheless, the problem persists.

There are three possibilities:

  1. The normalization function is somehow not getting called for certain events.

  2. Data containing a circular reference is being added to the event between normalization and serialization.

  3. The normalization function doesn't catch (and fix) all cases in which circular references exist.

In #3776, a debug flag was added which causes normalization to run twice, as a way to protect against possibility 1. As described in the above-linked issue, though, this hasn't solved the problem, at least not completely, as the serialization error is still occurring for some people.

This PR aims to improve on that initial debugging step, by making the following changes:

  • The initial attempt at serialization is wrapped in a try-catch, so that any errors that arise can be collected alongside the real event (as a JSONStringifyError tag and as a stacktrace in event.extra), rather than instead of it.

  • Events which go through the initial normalization are flagged internally, so that if the serializer encounters an event which doesn't have the flag, it can note that (as a skippedNormalization tag on the event). In theory this should never show up, but if it does, it points to possibility 1.

  • Renormalization has been moved so that it's part of the serialization process itself. If this fixes the problem, that points to possibility 2.

  • Renormalization has been wrapped in a try-catch, with a JSON.stringify error after renormalization event logged to Sentry (again with the error in extra data) in cases where it fails. This is another situation which should never happen, but if it does, it points to possibility 3.

Also, this is not specifically for debugging, but a bonus side effect of moving the renormalization to be part of serialization is that it allows us to only renormalize if theres's a problem, which eliminates a relatively computationally expensive operation in cases where it's not needed and therefore lets us ditch the debug flag.

P.S. Disclaimer: I know this isn't all that pretty, but my assumption is that this will stay in the SDK for a release or two while we (hopefully) finally solve the mystery, and then be pulled back out before we ship v7.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2022

size-limit report

Path Base Size (da7067d) Current Size Change
@sentry/browser - CDN Bundle (gzipped) 19.59 KB 19.7 KB +0.55% 🔺
@sentry/browser - CDN Bundle (minified) 62.51 KB 62.87 KB +0.58% 🔺
@sentry/browser - Webpack 22.11 KB 22.21 KB +0.47% 🔺
@sentry/browser - Webpack - gzip = false 75.63 KB 76.01 KB +0.5% 🔺
@sentry/react - Webpack 22.14 KB 22.24 KB +0.46% 🔺
@sentry/nextjs Client - Webpack 46.12 KB 46.23 KB +0.23% 🔺
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.12 KB 28.22 KB +0.39% 🔺

@lobsterkatie lobsterkatie force-pushed the kmclb-debug-circular-JSON-error-normalize-before-sentry-request branch from e65d1b1 to 6adc783 Compare January 20, 2022 03:16
packages/core/src/request.ts Outdated Show resolved Hide resolved
packages/core/src/request.ts Outdated Show resolved Hide resolved
packages/core/src/request.ts Outdated Show resolved Hide resolved
@lobsterkatie lobsterkatie force-pushed the kmclb-debug-circular-JSON-error-normalize-before-sentry-request branch from 6adc783 to b26c806 Compare January 21, 2022 23:20
@lobsterkatie lobsterkatie force-pushed the kmclb-debug-circular-JSON-error-normalize-before-sentry-request branch from b26c806 to e9ae54d Compare January 21, 2022 23:38
@lobsterkatie lobsterkatie merged commit 472cb0c into master Jan 24, 2022
@lobsterkatie lobsterkatie deleted the kmclb-debug-circular-JSON-error-normalize-before-sentry-request branch January 24, 2022 14:46
lobsterkatie added a commit that referenced this pull request Mar 25, 2022
…4780)

In #4425, various hacks were added to the SDK to try to diagnose the root cause of #2809. Unfortunately, one of those hacks (tagging when events are normalized) was applied to the pre-normalized version of the event rather than the normalized version that continues on through the event processing pipeline. This led to false positives, where events got tagged as if they'd skipped the normalization process even when they hadn't.

This fixes that by adding the flag to the normalized version of the event instead.
lobsterkatie added a commit that referenced this pull request Apr 6, 2022
…4870)

This is a follow up to #4425 and #4574, all in aid of debugging #2809, wherein serializing events leads to a circular reference error. One of the possible culprits is that the event is somehow skipping our usual normalization process, and one of the reasons that might happen is if `normalizeDepth` is set to something other than a number. We're already logging its value in problematic cases, and this change makes it so that we'll now log its type as well.
lobsterkatie added a commit that referenced this pull request Jun 16, 2022
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants