sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

LocalVariables integration - re-thrown errors can completely mess up frame variables

Open Bruno-DaSilva opened this issue 1 year ago • 3 comments

Is there an existing issue for this?

  • [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [x] I have reviewed the documentation https://docs.sentry.io/
  • [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

8.26.0

Framework Version

Node v20.12.2

Link to Sentry event

No response

Reproduction Example/SDK Setup

SDK setup:

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  includeLocalVariables: true,
});

Steps to Reproduce

  1. init sentry with the above config
  2. throw an exception
  3. catch the exception in another file or function (eg. a parent function)
  4. re-throw the error
  5. capture the re-thrown error

Expected Result

The error is reported to sentry with its ORIGINAL variables from where in was first thrown

Actual Result

The error is reported with only some frames with variables or no variables at all.

I dug into this - the error hash of the re-throw will match the error hash of the original error, and so the local variable frame state will overridden by the re-throw when the worker sends the re-throw frames. But then the re-throw location's stack and vars will not necessarily match the original frame's stack (and the re-throw's frame length may not match the error's frame) so it will effectively just null out the variables.

Bruno-DaSilva avatar Aug 18 '24 00:08 Bruno-DaSilva

I'm hoping with the digging I've done to root cause these it shouldn't require a high effort repro example -- but if it's needed I can create one (it'll just take me some time that I don't immediately have).

Bruno-DaSilva avatar Aug 18 '24 00:08 Bruno-DaSilva

I've created a PR #13418 that addresses this behaviour in worker.ts, but I'll need a maintainer to take it from here.

Bruno-DaSilva avatar Aug 18 '24 13:08 Bruno-DaSilva

Hey @Bruno-DaSilva thanks for writing in and for opening a PR!

We'll look into the issue and review the PR next week as this week is Hackweek at Sentry (see #13421).

Lms24 avatar Aug 19 '24 09:08 Lms24

This was released with https://github.com/getsentry/sentry-javascript/releases/tag/8.31.0 - thanks @Bruno-DaSilva for reporting, and ty @timfish for the fix!

AbhiPrasad avatar Sep 23 '24 13:09 AbhiPrasad