Skip to content
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

feat(node): Add LocalVariables integration to capture local variables to stack frames #6478

Merged
merged 24 commits into from Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
381748a
Add untested integration
timfish Dec 7, 2022
47bf353
Add LocalVariables integration
timfish Dec 7, 2022
f89101d
Fix dynamic loading of integration
timfish Dec 9, 2022
5c03a9d
Lint
timfish Dec 9, 2022
9a8f0dc
Improve
timfish Dec 9, 2022
726e874
Better defaultIntegrations
timfish Dec 9, 2022
4c2b05d
Merge remote-tracking branch 'upstream/master' into feat/stack-locals
timfish Dec 12, 2022
8635c2d
Merge branch 'feat/stack-locals' of https://github.com/timfish/sentry…
timfish Dec 12, 2022
815a1d6
Merge remote-tracking branch 'upstream/master' into feat/stack-locals
timfish Dec 12, 2022
d39fe92
Dont check for node version since v8 supports `inspector`
timfish Dec 12, 2022
65ea442
Simplify a bit more
timfish Dec 12, 2022
5d698a2
Merge branch 'feat/stack-locals' of https://github.com/timfish/sentry…
timfish Dec 12, 2022
5e0174b
Add some tests
timfish Dec 12, 2022
c0f47b6
fix for older node versions where we get a __proto__ array property
timfish Dec 13, 2022
b847980
Move option to _experiments
timfish Dec 13, 2022
d402354
changes from review
timfish Dec 14, 2022
c842fb3
Minor changes
timfish Dec 14, 2022
93cb95e
Add unit tests
timfish Dec 15, 2022
e3d11f3
remove lint disable
timfish Dec 15, 2022
e2b1f71
Remove nullable stackParser property
timfish Dec 15, 2022
0b7fd39
I miss test lint warnings
timfish Dec 15, 2022
d5d4700
Merge remote-tracking branch 'upstream/master' into feat/stack-locals
timfish Dec 15, 2022
2c144d0
Add empty options object as first constructor param
timfish Jan 9, 2023
bd351cc
jsdocs
timfish Jan 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,35 @@
/* eslint-disable no-unused-vars */
const Sentry = require('@sentry/node');

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
_experiments: { includeStackLocals: true },
beforeSend: event => {
// eslint-disable-next-line no-console
console.log(JSON.stringify(event));
},
});

process.on('uncaughtException', () => {
// do nothing - this will prevent the Error below from closing this process
});

class Some {
two(name) {
throw new Error('Enough!');
}
}

function one(name) {
const arr = [1, '2', null];
const obj = {
name,
num: 5,
};

const ty = new Some();

ty.two(name);
}

one('some name');
@@ -0,0 +1,34 @@
/* eslint-disable no-unused-vars */
const Sentry = require('@sentry/node');

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
beforeSend: event => {
// eslint-disable-next-line no-console
console.log(JSON.stringify(event));
},
});

process.on('uncaughtException', () => {
// do nothing - this will prevent the Error below from closing this process
});

class Some {
two(name) {
throw new Error('Enough!');
}
}

function one(name) {
const arr = [1, '2', null];
const obj = {
name,
num: 5,
};

const ty = new Some();

ty.two(name);
}

one('some name');
@@ -0,0 +1,54 @@
import { Event } from '@sentry/node';
import * as childProcess from 'child_process';
import * as path from 'path';

describe('LocalVariables integration', () => {
test('Should not include local variables by default', done => {
expect.assertions(2);

const testScriptPath = path.resolve(__dirname, 'no-local-variables.js');

childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (_, stdout) => {

Check warning

Code scanning / CodeQL

Shell command built from environment values

This shell command depends on an uncontrolled [absolute path](1).
const event = JSON.parse(stdout) as Event;

const frames = event.exception?.values?.[0].stacktrace?.frames || [];
const lastFrame = frames[frames.length - 1];

expect(lastFrame.vars).toBeUndefined();

const penultimateFrame = frames[frames.length - 2];

expect(penultimateFrame.vars).toBeUndefined();

done();
});
});

test('Should include local variables when enabled', done => {
expect.assertions(4);

const testScriptPath = path.resolve(__dirname, 'local-variables.js');

childProcess.exec(`node ${testScriptPath}`, { encoding: 'utf8' }, (_, stdout) => {

Check warning

Code scanning / CodeQL

Shell command built from environment values

This shell command depends on an uncontrolled [absolute path](1).
const event = JSON.parse(stdout) as Event;

const frames = event.exception?.values?.[0].stacktrace?.frames || [];
const lastFrame = frames[frames.length - 1];

expect(lastFrame.function).toBe('Some.two');
expect(lastFrame.vars).toEqual({ name: 'some name' });

const penultimateFrame = frames[frames.length - 2];

expect(penultimateFrame.function).toBe('one');
expect(penultimateFrame.vars).toEqual({
name: 'some name',
arr: [1, '2', null],
obj: { name: 'some name', num: 5 },
ty: '<Some>',
});

done();
});
});
});
1 change: 1 addition & 0 deletions packages/node/src/integrations/index.ts
Expand Up @@ -7,3 +7,4 @@ export { Modules } from './modules';
export { ContextLines } from './contextlines';
export { Context } from './context';
export { RequestData } from './requestdata';
export { LocalVariables } from './localvariables';