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
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
381748a
Add untested integration
timfish 47bf353
Add LocalVariables integration
timfish f89101d
Fix dynamic loading of integration
timfish 5c03a9d
Lint
timfish 9a8f0dc
Improve
timfish 726e874
Better defaultIntegrations
timfish 4c2b05d
Merge remote-tracking branch 'upstream/master' into feat/stack-locals
timfish 8635c2d
Merge branch 'feat/stack-locals' of https://github.com/timfish/sentry…
timfish 815a1d6
Merge remote-tracking branch 'upstream/master' into feat/stack-locals
timfish d39fe92
Dont check for node version since v8 supports `inspector`
timfish 65ea442
Simplify a bit more
timfish 5d698a2
Merge branch 'feat/stack-locals' of https://github.com/timfish/sentry…
timfish 5e0174b
Add some tests
timfish c0f47b6
fix for older node versions where we get a __proto__ array property
timfish b847980
Move option to _experiments
timfish d402354
changes from review
timfish c842fb3
Minor changes
timfish 93cb95e
Add unit tests
timfish e3d11f3
remove lint disable
timfish e2b1f71
Remove nullable stackParser property
timfish 0b7fd39
I miss test lint warnings
timfish d5d4700
Merge remote-tracking branch 'upstream/master' into feat/stack-locals
timfish 2c144d0
Add empty options object as first constructor param
timfish bd351cc
jsdocs
timfish File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
packages/node-integration-tests/suites/public-api/LocalVariables/local-variables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* eslint-disable no-unused-vars */ | ||
const Sentry = require('@sentry/node'); | ||
|
||
Sentry.init({ | ||
dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
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', new Date()]; | ||
const obj = { | ||
name, | ||
num: 5, | ||
}; | ||
|
||
const ty = new Some(); | ||
|
||
ty.two(name); | ||
} | ||
|
||
one('some name'); |
34 changes: 34 additions & 0 deletions
34
packages/node-integration-tests/suites/public-api/LocalVariables/no-local-variables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', new Date()]; | ||
const obj = { | ||
name, | ||
num: 5, | ||
}; | ||
|
||
const ty = new Some(); | ||
|
||
ty.two(name); | ||
} | ||
|
||
one('some name'); |
54 changes: 54 additions & 0 deletions
54
packages/node-integration-tests/suites/public-api/LocalVariables/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) => { | ||
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(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Shell command built from environment values