sentry-javascript: `@sentry/node` with `includeLocalVariables` is not showing anything about local variables on any errors on the Sentry dashboard

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/node

SDK Version

7.64.0 7.73.0

Framework Version

Node 18.15.0

Link to Sentry event

[private]

SDK Setup

import * as Sentry from '@sentry/node'

Sentry.init({
  environment: ...,
  dsn: ...,
  tracesSampleRate: 1.0,
  includeLocalVariables: true,
  integrations: [
    new Sentry.Integrations.LocalVariables({
      captureAllExceptions: true,
    }),
  ],
  debug: true,
})

Steps to Reproduce

I’m trying to use @sentry/node’s new includeLocalVariables (https://blog.sentry.io/local-variables-for-nodejs-in-sentry/). I’m using Sentry SDK 7.73.0 with Node 18.15.0 (TypeScript, without ESM modules), which should work fine. But my caught errors do not show any local variables in the Sentry Dashboard.

Expected Result

Each caught error would the values of show local variables as such on the Sentry dashboard (picture from the blog post):

screenshot from Sentry's linked blogpost that showcases local variables

Actual Result

The errors show up fine as before, but no local variables can be seen anywhere from the dashboard:

┆Issue is synchronized with this Jira Improvement by Unito

About this issue

  • Original URL
  • State: open
  • Created 10 months ago
  • Reactions: 2
  • Comments: 36 (9 by maintainers)

Most upvoted comments

My question was that would it make sense for @sentry/node’s captureException() (which is used inside Sentry.Handlers.errorHandler()) be altered so that one could include local variables on the error on a case-by-case basis.

If it is possible, yes that would make sense, however, it is likely not. The idea is not bad.

Node does not provide a dedicated API to grab local variables in the current scope, but it is possible with Node.js’ debugger/inspector API, which we are leveraging here. If you think it through, you can’t retroactively tell the debugger to grab the local variable state as it was when an error was thrown. However, that’s exactly what we would need to do, in order to make what you suggest happen. I scanned the debugger API and couldn’t find a way (maybe I missed something though).

For the above reason, we need this all-or-nothing option. Either we can grab the variables in time, or we don’t at all.

Which does not sound at all something like I would want to enable.

We thought people might not wanna have this on by default since this obviously impacts performance, so we added this option. Makes sense I think. This is addon functionality, not essential for the SDK to work. Feel free to leave it turned off.

In case you care about the technical details feel free to take a look at our code for this functionality. It is all within one file!

https://github.com/getsentry/sentry-javascript/blob/9dc0f1243625cd1bdb647f0427bc6adc06cba561/packages/node/src/integrations/localvariables.ts#L262

Updated the original description to include the attempted changes.