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

fix(utils): Normalize when serializing envelope #5851

Merged
merged 2 commits into from Sep 29, 2022

Conversation

lforst
Copy link
Member

@lforst lforst commented Sep 29, 2022

Since #2809 keeps being necrobumped I decided to look into it once more.

Apparently unnormalized data keeps slipping through up until we serialize envelopes. This causes the JSON.stringify call to fail and throw, right before we were about to report an error event. Not ideal.

My proposed fix for now - and I am definitely not all for it - is to simply wrap the JSON.stringify call in a try-catch and normalize the entire payload with infinite recursion depth once more, in case that call fails.

This has an obvious performance impact, especially since we know that when JSON.stringify fails, it has some unnormalized data that might be very big and recursive - potentially even sending payloads that are too big.

// In case, despite all our efforts to keep `payload` circular-dependency-free, `JSON.strinify()` still
// fails, we try again after normalizing it again with infinite normalization depth. This of course has a
// performance impact but in this case a performance hit is better than throwing.
stringifiedPayload = JSON.stringify(normalize(payload));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should throw an error to Sentry as well here? Maybe attach the event_id so folks can report back about why this is happening (like we can inspect the fully normalized payload).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to log, what parts of the payload contained the circular reference, just so we can close these gaps. We discussed some ideas:

  • Capture an additional exception here with the circ-dep path and let users report back to us.
  • Set a specific field in extra and show a warning on the Sentry product to report back to us.
  • Set a specific field in the payload with the circ-dep path and log that field in relay.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 29, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.49 KB (+0.11% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 60.29 KB (+0.11% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.11 KB (+0.1% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 53.22 KB (+0.11% 🔺)
@sentry/browser - Webpack (gzipped + minified) 19.83 KB (-0.11% 🔽)
@sentry/browser - Webpack (minified) 64.56 KB (+0.1% 🔺)
@sentry/react - Webpack (gzipped + minified) 19.85 KB (-0.09% 🔽)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.75 KB (-0.07% 🔽)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.94 KB (+0.08% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.38 KB (+0.08% 🔺)

@lforst lforst merged commit 18cc680 into master Sep 29, 2022
@lforst lforst deleted the lforst-serialize-envelope-normalize branch September 29, 2022 11:04
@lforst lforst self-assigned this Sep 29, 2022
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

2 participants