Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(node): Fix local variables capturing for out-of-app frames #17545

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

Open
JealousGx wants to merge 11 commits into getsentry:develop
base: develop
Choose a base branch
Loading
from JealousGx:fix/local-variables-12588
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit Hold shift + click to select a range
d92b0a0
fix(node-core): Fix local variables capturing for out-of-app frames (...
JealousGx Sep 6, 2025
7ca795c
fix(local-variables): Clean up function assignment and fix syntax in ...
JealousGx Sep 6, 2025
5323928
fix(local-variables): Refine condition for skipping out-of-app frames...
JealousGx Sep 6, 2025
7fb4542
fix(node-core): Fix race condition in local variables integration
JealousGx Sep 6, 2025
662ab6d
Merge branch 'develop' into fix/local-variables-12588
JealousGx Sep 6, 2025
367ef5c
test(local-variables): Add integration tests for local variables in o...
JealousGx Sep 13, 2025
76893c5
refactor(local-variables): Remove test helper methods and related tests
JealousGx Sep 13, 2025
6ff90dc
refactor(local-variables): Remove local variables async integration t...
JealousGx Sep 13, 2025
c81dc55
Merge branch 'develop' into fix/local-variables-12588
JealousGx Sep 15, 2025
d2a40cf
fix(logging-transport): Correct import path for loggingTransport to r...
JealousGx Sep 19, 2025
651d3f3
Merge branch 'develop' into fix/local-variables-12588
JealousGx Sep 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable no-unused-vars */

const Sentry = require('@sentry/node');
// const { loggingTransport } = require('@sentry-internal/node-integration-tests'); is throwing error that package not found, so using relative path
Copy link
Member

@AbhiPrasad AbhiPrasad Sep 17, 2025

Choose a reason for hiding this comment

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

This shouldn't be happening, are you running yarn build in the root of the repo? You might have to run yarn clean and delete node modules to get stuff in a good state.

Copy link
Author

@JealousGx JealousGx Sep 18, 2025

Choose a reason for hiding this comment

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

Well, unfortunately, it's happening even after clean installation and building.

The steps I took:

  • Delete root node_modules directory
  • yarn
  • yarn clean
  • yarn build
  • Make sure to import loggingTransport from @sentry-internal/node-integration-tests
  • DEBUG=true yarn workspace @sentry-internal/node-integration-tests test -- LocalVariables

You will get this error:

Error: Cannot find module '/Users/my-pc/sentry-javascript/node_modules/@sentry-internal/node-integration-tests/build/cjs/index.js'. Please verify that the package.json has a valid "main" entry
 at tryPackage (node:internal/modules/cjs/loader:515:19)
 at Function._findPath (node:internal/modules/cjs/loader:800:18)
 at Function._resolveFilename (node:internal/modules/cjs/loader:1391:27)
 at defaultResolveImpl (node:internal/modules/cjs/loader:1061:19)
 at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1066:22)
 at Function._load (node:internal/modules/cjs/loader:1215:37)
 at TracingChannel.traceSync (node:diagnostics_channel:322:14)
 at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
 at Module.require (node:internal/modules/cjs/loader:1491:12)
 at require (node:internal/modules/helpers:135:16) {
 code: 'MODULE_NOT_FOUND',
 path: '/Users/my-pc/sentry-javascript/node_modules/@sentry-internal/node-integration-tests/package.json',
 requestPath: '@sentry-internal/node-integration-tests'
}

Copy link
Member

@AbhiPrasad AbhiPrasad Sep 18, 2025

Choose a reason for hiding this comment

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

I wonder if the issue is yarn workspace, if you cd into the directory and run the tests there directly do you get the same issues? I'm unfortunately not able to reproduce.

Copy link
Author

@JealousGx JealousGx Sep 19, 2025

Choose a reason for hiding this comment

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

Alright yeah. My bad. I was building in the root directory. I should've run the build command in the node-integration-tests directory as well. Working fine now. Let's wait for @timfish for their reply to the last comment now.

const { loggingTransport } = require('../../../src/index.ts');

// make sure to create the following file with the following content:
// function out_of_app_function() {
// const outOfAppVar = 'out of app value';
// throw new Error('out-of-app error');
// }

// module.exports = { out_of_app_function };
Comment on lines 3 to 12
Copy link
Member

@AbhiPrasad AbhiPrasad Sep 17, 2025

Choose a reason for hiding this comment

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

This is far too brittle, but not sure how to best do this. Maybe @timfish you have some ideas?

Copy link
Author

@JealousGx JealousGx Sep 18, 2025

Choose a reason for hiding this comment

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

We can either do this or use beforeSend method in the init to modify the frames and include the necessary details. If there are other ways to achieve this, we could try them as well.


const { out_of_app_function } = require('./node_modules/test-module/out-of-app-function.js');

function in_app_function() {
const inAppVar = 'in app value';
out_of_app_function();
}

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
transport: loggingTransport,
includeLocalVariables: true,
// either set each frame's in_app flag manually or import the `out_of_app_function` from a node_module directory
// beforeSend: (event) => {
// event.exception?.values?.[0]?.stacktrace?.frames?.forEach(frame => {
// if (frame.function === 'out_of_app_function') {
// frame.in_app = false;
// }
// });
// return event;
// },
});

setTimeout(async () => {
try {
in_app_function();
} catch (e) {
Sentry.captureException(e);
await Sentry.flush();

return null;
}
}, 1000);
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable no-unused-vars */

const Sentry = require('@sentry/node');
// const { loggingTransport } = require('@sentry-internal/node-integration-tests'); is throwing error that package not found, so using relative path
const { loggingTransport } = require('../../../src/index.ts');

const { out_of_app_function } = require('./node_modules/test-module/out-of-app-function.js');
Copy link

@cursor cursor bot Sep 13, 2025

Choose a reason for hiding this comment

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

Bug: Missing Dependency in Test Setup

The new local variables test files depend on ./node_modules/test-module/out-of-app-function.js. This module isn't provided in the commit or created by the test setup, which will lead to a "module not found" error at runtime. This indicates an incomplete test setup, as also suggested by the manual creation comments.

Additional Locations (1)

Fix in Cursor Fix in Web


Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
transport: loggingTransport,
includeLocalVariables: true,
integrations: [
Sentry.localVariablesIntegration({
includeOutOfAppFrames: true,
}),
],
// either set each frame's in_app flag manually or import the `out_of_app_function` from a node_module directory
// beforeSend: (event) => {
// event.exception?.values?.[0]?.stacktrace?.frames?.forEach(frame => {
// if (frame.function === 'out_of_app_function') {
// frame.in_app = false;
// }
// });
// return event;
// },
});

function in_app_function() {
const inAppVar = 'in app value';
out_of_app_function();
}

setTimeout(async () => {
try {
in_app_function();
} catch (e) {
Sentry.captureException(e);
await Sentry.flush();
return null;
}
}, 1000);
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,44 @@ describe('LocalVariables integration', () => {
.start()
.completed();
});

test('adds local variables to out of app frames when includeOutOfAppFrames is true', async () => {
await createRunner(__dirname, 'local-variables-out-of-app.js')
.expect({
event: event => {
const frames = event.exception?.values?.[0]?.stacktrace?.frames || [];

const inAppFrame = frames.find(frame => frame.function === 'in_app_function');
const outOfAppFrame = frames.find(frame => frame.function === 'out_of_app_function');

expect(inAppFrame?.vars).toEqual({ inAppVar: 'in app value' });
expect(inAppFrame?.in_app).toEqual(true);

expect(outOfAppFrame?.vars).toEqual({ outOfAppVar: 'out of app value' });
expect(outOfAppFrame?.in_app).toEqual(false);
},
})
.start()
.completed();
});

test('does not add local variables to out of app frames by default', async () => {
await createRunner(__dirname, 'local-variables-out-of-app-default.js')
.expect({
event: event => {
const frames = event.exception?.values?.[0]?.stacktrace?.frames || [];

const inAppFrame = frames.find(frame => frame.function === 'in_app_function');
const outOfAppFrame = frames.find(frame => frame.function === 'out_of_app_function');

expect(inAppFrame?.vars).toEqual({ inAppVar: 'in app value' });
expect(inAppFrame?.in_app).toEqual(true);

expect(outOfAppFrame?.vars).toBeUndefined();
expect(outOfAppFrame?.in_app).toEqual(false);
},
})
.start()
.completed();
});
});
6 changes: 6 additions & 0 deletions packages/node-core/src/integrations/local-variables/common.ts
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ export interface LocalVariablesIntegrationOptions {
* Maximum number of exceptions to capture local variables for per second before rate limiting is triggered.
*/
maxExceptionsPerSecond?: number;
/**
* When true, local variables will be captured for all frames, including those that are not in_app.
*
* Defaults to `false`.
*/
includeOutOfAppFrames?: boolean;
}

export interface LocalVariablesWorkerArgs extends LocalVariablesIntegrationOptions {
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const localVariablesAsyncIntegration = defineIntegration(((
if (
// We need to have vars to add
frameLocalVariables.vars === undefined ||
// We're not interested in frames that are not in_app because the vars are not relevant
frame.in_app === false ||
// Only skip out-of-app frames if includeOutOfAppFrames is not true
(frame.in_app === false && integrationOptions.includeOutOfAppFrames !== true) ||
// The function names need to match
!functionNamesMatch(frame.function, frameLocalVariables.function)
) {
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /