Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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,45 @@
/* eslint-disable no-unused-vars */

const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

// 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 };

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://[email protected]/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,41 @@
/* eslint-disable no-unused-vars */

const Sentry = require('@sentry/node');
const { loggingTransport } = require('@sentry-internal/node-integration-tests');

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

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://[email protected]/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);
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,44 @@
.start()
.completed();
});

test('adds local variables to out of app frames when includeOutOfAppFrames is true', async () => {

Check failure on line 131 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (20) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > adds local variables to out of app frames when includeOutOfAppFrames is true

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:131:3

Check failure on line 131 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (24) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > adds local variables to out of app frames when includeOutOfAppFrames is true

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:131:3

Check failure on line 131 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (22) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > adds local variables to out of app frames when includeOutOfAppFrames is true

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:131:3

Check failure on line 131 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (24) (TS 3.8) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > adds local variables to out of app frames when includeOutOfAppFrames is true

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:131:3

Check failure on line 131 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (18) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > adds local variables to out of app frames when includeOutOfAppFrames is true

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:131:3
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 () => {

Check failure on line 151 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (20) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > does not add local variables to out of app frames by default

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:151:3

Check failure on line 151 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (24) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > does not add local variables to out of app frames by default

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:151:3

Check failure on line 151 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (22) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > does not add local variables to out of app frames by default

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:151:3

Check failure on line 151 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (24) (TS 3.8) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > does not add local variables to out of app frames by default

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:151:3

Check failure on line 151 in dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

View workflow job for this annotation

GitHub Actions / Node (18) Integration Tests

suites/public-api/LocalVariables/test.ts > LocalVariables integration > does not add local variables to out of app frames by default

Error: Test timed out in 15000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ suites/public-api/LocalVariables/test.ts:151:3
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
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
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
Loading