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(node): Log entire error object in OnUncaughtException #8876

Merged
merged 3 commits into from
Aug 28, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Aug 28, 2023

In our OnUncaughtException integration, we have to emulate Node's default behaviour of logging errors to the console.
For some reason though, we only logged the stack trace of an error with a stack trace instead of the entire error object.

As reported in #8856, this causes additional properties on the error (such as cause) not to be logged anymore which doesn't reflect Node's default behaviour (see issue for comparison). This PR simplifies the console.error call to just always log the entire error.

I tried tracing back why we do this but it seems like we added this when moving from raven-node to @sentry/node. I didn't find this before in Raven and there's no explanation as to why we started doing it in @sentry/node. So I guess it should be fine to change this.

Side-node: As already mentioned in #1661 (comment), we should consider moving to UnhandledExceptionMonitor in v8, especially if we drop Node <=12 support.

closes #8856

Update: Seems like console.error(error) only prints additional properties since Node 16. Nothing much we can do here so I adjusted the test to take this into accound.

@Lms24 Lms24 changed the title fix(node): Log entire error object in OnUncaughtException fix(node): Log entire error object in OnUncaughtException Aug 28, 2023
@Lms24 Lms24 requested review from mydea and AbhiPrasad August 28, 2023 09:33
Copy link
Member

@lforst lforst left a comment

Choose a reason for hiding this comment

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

Reasonable

@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 75.22 KB (0%)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.2 KB (0%)
@sentry/browser - Webpack (gzipped) 21.85 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 69.75 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 28.21 KB (+0.01% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 20.18 KB (+0.01% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 220.06 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 84.89 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 59.86 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.11 KB (+0.01% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 75.24 KB (0%)
@sentry/react - Webpack (gzipped) 21.88 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 93.04 KB (0%)
@sentry/nextjs Client - Webpack (gzipped) 50.73 KB (0%)


const testScriptPath = path.resolve(__dirname, 'log-entire-error-to-console.js');

childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (err, stderr) => {

Check warning

Code scanning / CodeQL

Shell command built from environment values Medium test

This shell command depends on an uncontrolled
absolute path
.
@Lms24 Lms24 enabled auto-merge (squash) August 28, 2023 10:58
@Lms24 Lms24 merged commit 5afb861 into develop Aug 28, 2023
58 checks passed
@Lms24 Lms24 deleted the lms/fix-node-uncaught-exception-console-log branch August 28, 2023 11:09
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.

Printed errors should show cause
2 participants