Skip to content

Commit e3a1efc

Browse files
JealousGxisaacs
authored andcommitted
test(local-variables): Add integration tests for local variables in out-of-app frames
1 parent 98bee7b commit e3a1efc

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* eslint-disable no-unused-vars */
2+
3+
const Sentry = require('@sentry/node');
4+
// const { loggingTransport } = require('@sentry-internal/node-integration-tests'); is throwing error that package not found, so using relative path
5+
const { loggingTransport } = require('../../../src/index.ts');
6+
7+
// make sure to create the following file with the following content:
8+
// function out_of_app_function() {
9+
// const outOfAppVar = 'out of app value';
10+
// throw new Error('out-of-app error');
11+
// }
12+
13+
// module.exports = { out_of_app_function };
14+
15+
const { out_of_app_function } = require('./node_modules/test-module/out-of-app-function.js');
16+
17+
function in_app_function() {
18+
const inAppVar = 'in app value';
19+
out_of_app_function();
20+
}
21+
22+
Sentry.init({
23+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
24+
transport: loggingTransport,
25+
includeLocalVariables: true,
26+
// either set each frame's in_app flag manually or import the `out_of_app_function` from a node_module directory
27+
// beforeSend: (event) => {
28+
// event.exception?.values?.[0]?.stacktrace?.frames?.forEach(frame => {
29+
// if (frame.function === 'out_of_app_function') {
30+
// frame.in_app = false;
31+
// }
32+
// });
33+
// return event;
34+
// },
35+
});
36+
37+
setTimeout(async () => {
38+
try {
39+
in_app_function();
40+
} catch (e) {
41+
Sentry.captureException(e);
42+
await Sentry.flush();
43+
44+
return null;
45+
}
46+
}, 1000);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable no-unused-vars */
2+
3+
const Sentry = require('@sentry/node');
4+
// const { loggingTransport } = require('@sentry-internal/node-integration-tests'); is throwing error that package not found, so using relative path
5+
const { loggingTransport } = require('../../../src/index.ts');
6+
7+
const { out_of_app_function } = require('./node_modules/test-module/out-of-app-function.js');
8+
9+
Sentry.init({
10+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
11+
transport: loggingTransport,
12+
includeLocalVariables: true,
13+
integrations: [
14+
Sentry.localVariablesIntegration({
15+
includeOutOfAppFrames: true,
16+
}),
17+
],
18+
// either set each frame's in_app flag manually or import the `out_of_app_function` from a node_module directory
19+
// beforeSend: (event) => {
20+
// event.exception?.values?.[0]?.stacktrace?.frames?.forEach(frame => {
21+
// if (frame.function === 'out_of_app_function') {
22+
// frame.in_app = false;
23+
// }
24+
// });
25+
// return event;
26+
// },
27+
});
28+
29+
function in_app_function() {
30+
const inAppVar = 'in app value';
31+
out_of_app_function();
32+
}
33+
34+
setTimeout(async () => {
35+
try {
36+
in_app_function();
37+
} catch (e) {
38+
Sentry.captureException(e);
39+
await Sentry.flush();
40+
return null;
41+
}
42+
}, 1000);

dev-packages/node-integration-tests/suites/public-api/LocalVariables/test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,44 @@ describe('LocalVariables integration', () => {
127127
.start()
128128
.completed();
129129
});
130+
131+
test('adds local variables to out of app frames when includeOutOfAppFrames is true', async () => {
132+
await createRunner(__dirname, 'local-variables-out-of-app.js')
133+
.expect({
134+
event: event => {
135+
const frames = event.exception?.values?.[0]?.stacktrace?.frames || [];
136+
137+
const inAppFrame = frames.find(frame => frame.function === 'in_app_function');
138+
const outOfAppFrame = frames.find(frame => frame.function === 'out_of_app_function');
139+
140+
expect(inAppFrame?.vars).toEqual({ inAppVar: 'in app value' });
141+
expect(inAppFrame?.in_app).toEqual(true);
142+
143+
expect(outOfAppFrame?.vars).toEqual({ outOfAppVar: 'out of app value' });
144+
expect(outOfAppFrame?.in_app).toEqual(false);
145+
},
146+
})
147+
.start()
148+
.completed();
149+
});
150+
151+
test('does not add local variables to out of app frames by default', async () => {
152+
await createRunner(__dirname, 'local-variables-out-of-app-default.js')
153+
.expect({
154+
event: event => {
155+
const frames = event.exception?.values?.[0]?.stacktrace?.frames || [];
156+
157+
const inAppFrame = frames.find(frame => frame.function === 'in_app_function');
158+
const outOfAppFrame = frames.find(frame => frame.function === 'out_of_app_function');
159+
160+
expect(inAppFrame?.vars).toEqual({ inAppVar: 'in app value' });
161+
expect(inAppFrame?.in_app).toEqual(true);
162+
163+
expect(outOfAppFrame?.vars).toBeUndefined();
164+
expect(outOfAppFrame?.in_app).toEqual(false);
165+
},
166+
})
167+
.start()
168+
.completed();
169+
});
130170
});

0 commit comments

Comments
 (0)