Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(node): Add
LocalVariables
integration to capture local variabl…
…es to stack frames (#6478)
- Loading branch information
Showing
8 changed files
with
4,032 additions
and
0 deletions.
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', | ||
_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'); |
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', null]; | ||
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) => { | ||
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.