Hello, I'm exploring Sentry for the company I'm working at. I'm using the nodejs-express SDK to track errors in our Apollo GraphQL server running as an Express app.
I was able to capture an error but the event doesn't include local variables.
I want to be able to use Sentry the same way I use a debugger where I'm able to see the actual values of all variables in a given scope.
I tried to include both includeLocalVariables: true and Sentry.localVariablesIntegration() in Sentry.init() but it doesn't work for me. Help will be much appreciated!
#Include local variables
70 messages · Page 1 of 1 (latest)
hey @young remnant
are you using ESM? as per https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/localvariables/ ESM has some issues with local variables support
Add local variables to exception frames. (default)
Thanks for the reply. No, I'm not using ESM. Also, according to the documentation, there shouldn't be an issue when the error is handled which is the case I was testing.
if you enable debug: true, the sdk outputs more details about its internals
could you enable that option in your Sentry.init call and then share your debug output?
These are the logs from the minute I invoked the request that causes the error.
The only warning I see is [warn]: Discarded session because of missing or non-string release. Can it be related?
no that's not related.
are you capturing an error here?
Yeah.. look for “Sentry Logger [log]: Captured error event Cannot read properties of undefined (reading 'map')”
can you share the debug logs at startup? Does it show the localvariables integration getting installed?
Yeah..it's there
and running in commonjs hmm. Super strange.
It's hard to know what exactly is going wrong without a reproduction of some kind. Are you able to share that?
It's a proprietary code unfortunately...
But it's supposed to work with this kind of setup, right? Meaning, an Apollo GraphQL server that runs on top of an Express app..
@late reef I created a MRE
thanks! we'll take a look on monday. This should be working, but perhaps there is a case we missed
think I figured it out! opened a PR to fix: https://github.com/getsentry/sentry-javascript/pull/16702
thanks for the reproduction, really helped a lot
Awesome.. I'm glad it worked out. Thanks!
@late reef Any estimation when this fix will be released?
hopefully today! otherwise tomorrow morning
Great..thx!
@late reef I believe it didn't fix the issue..I still can't see local variables.
I used the MRE to test it..
I don't even see args on the bottom
works for me on latest SDK version 9.32.0
Weird..I'm also using the latest version and that's what I'm getting..
So the screenshot you shared was a result of an older version?
nope, it was from the latest SDK version that I just installed and ran
if you add beforeSend to your Sentry.init call, you can debug the payload locally
beforeSend: (event, hint) => {
console.log(JSON.stringify(event, null, 2));
return null;
},
this got me something that looks like so:
{
"filename": "/Users/abhijeetprasad/customer/mini-graphql/app.js",
"module": "app",
"function": "Object.testSentry",
"lineno": 32,
"colno": 14,
"in_app": true,
"pre_context": [
" }",
"`;",
"",
"const resolvers = {",
" Query: {",
" testSentry: (args) => {",
" try {"
],
"context_line": " args.foo.map((x) => x);",
"post_context": [
" return true;",
" } catch (error) {",
" Sentry.captureException(error);",
" return false;",
" }",
" },",
" },"
],
"vars": {
"args": "<undefined>"
}
}
shouldn't args be an empty object though?
I guess it depends on what you're passing. I was assuming you're passing an object..
Ok I'll give beforeSend a try
I don't have a event.vars entry
vars are associated to an individual stacktrace frame
I don't see it there either.
I ran event.exception.values.flatMap(v => v.stacktrace.frames.map(f => f.vars)) and I'm getting an array of a bunch of undefined as opposed to "<undefined>"
Also, in your screenshot you can see the args in the bottom but in mine it's missing..
This is how my request looks like. Are you sending the same thing?
I was just doing
curl -X POST http://localhost:4434/graphql \
-H "Content-Type: application/json" \
-d '{"query": "query { testSentry(input: {}) }"}'
but if I set variables to an empty object I get the same thing
@young remnant are you able to send a link to the sentry event? Or if you scroll down to the bottom, what does the SDK section show?
are you able to make it work in a non-graphql app?
also maybe OS/node version related - what OS/node version are you on?
Haven't tried it on a non-graphql app yet..
I tried running the following script and I still don't see vars in the stacktrace frame
require('./instrument.js');
const Sentry = require('@sentry/node');
const dummy = (args) => {
try {
args.foo.map((x) => x);
} catch (error) {
Sentry.captureException(error);
}
return true;
};
dummy({});
so for you above example, it's because the local variables inspector is async
require("./instrument.js");
const Sentry = require("@sentry/node");
const dummy = (args) => {
let x = 1;
try {
args.foo.map((x) => x);
} catch (error) {
Sentry.captureException(error);
}
return true;
};
async function run() {
await new Promise((resolve) => setTimeout(resolve, 1000));
dummy({});
}
run();
you'll see vars for this
@tawny flume I guess we have no way to wait for the inspector before capturing errors right?
Oh I see..I'm afk at the moment. I'll try out your modified script later on today
@late reef That's crazy! I still don't get any vars
Can it be a project setting?
theres no project setting for this, but you said it's not showing up in beforeSend right? that means the sdk itself isn't flushing it
yeah you're right..
The contexts are pretty much the same as yours...maybe I should move to Canada
Is there anything else I can do to help you figure this out? I'm really out of ideas..
it's seems like a local issue since even the non-graphql example doesn't work by me.
you're always welcome up north 😄
I'll try something else out tommorow
Lol thx!
I was debugging the non-graphql example and it seems like a fallback logic is being executed in my case. Is that something that can be relevant?
Another, probably more relevant, clue is that in this function, common.LOCAL_VARIABLES_KEY in hint.originalException is false. That means no local variables are attached to the originalException object.
Finally got it!!
Apparently I needed to set includeLocalVariables in the init to true 😅
I thought that was the default behavior. Also, it's disabled if I'm using a debugger so it will fetch the local variables only if I run without the debugger. I also tested the graphql app and it works.
Thank you very much and sorry for the hassle..
ahhhh okay shoot
glad we got it figured out!
thanks for debugging with me!
@young remnant shoot me an email at aprasad @ sentry . io (remove the spaces), we can get you some sentry swag for your help
@late reef Sounds great..thx!