-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 scope to ANR events (v7) (#11267)
Backport of #11256 Scope wasn't working for the deprecated export (pre. integration) so I didn't spend any time trying to fix it and just don't test this scope feature for that.
- Loading branch information
Showing
9 changed files
with
230 additions
and
18 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -14,6 +14,9 @@ Sentry.init({ | |
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 100 })], | ||
}); | ||
|
||
Sentry.setUser({ email: '[email protected]' }); | ||
Sentry.addBreadcrumb({ message: 'important message!' }); | ||
|
||
function longWork() { | ||
for (let i = 0; i < 20; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
|
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 |
---|---|---|
|
@@ -15,6 +15,9 @@ Sentry.init({ | |
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 100 })], | ||
}); | ||
|
||
Sentry.setUser({ email: '[email protected]' }); | ||
Sentry.addBreadcrumb({ message: 'important message!' }); | ||
|
||
function longWork() { | ||
for (let i = 0; i < 20; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
|
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 |
---|---|---|
|
@@ -15,6 +15,9 @@ Sentry.init({ | |
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 100 })], | ||
}); | ||
|
||
Sentry.setUser({ email: '[email protected]' }); | ||
Sentry.addBreadcrumb({ message: 'important message!' }); | ||
|
||
function longWork() { | ||
for (let i = 0; i < 20; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
|
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 |
---|---|---|
|
@@ -15,6 +15,9 @@ Sentry.init({ | |
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 100 })], | ||
}); | ||
|
||
Sentry.setUser({ email: '[email protected]' }); | ||
Sentry.addBreadcrumb({ message: 'important message!' }); | ||
|
||
function longWork() { | ||
for (let i = 0; i < 20; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
|
53 changes: 53 additions & 0 deletions
53
dev-packages/node-integration-tests/suites/anr/isolated.mjs
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,53 @@ | ||
import * as assert from 'assert'; | ||
import * as crypto from 'crypto'; | ||
|
||
import * as Sentry from '@sentry/node'; | ||
|
||
setTimeout(() => { | ||
process.exit(); | ||
}, 10000); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
debug: true, | ||
autoSessionTracking: false, | ||
integrations: [Sentry.anrIntegration({ captureStackTrace: true, anrThreshold: 100 })], | ||
}); | ||
|
||
async function longWork() { | ||
await new Promise(resolve => setTimeout(resolve, 1000)); | ||
|
||
for (let i = 0; i < 20; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
assert.ok(hash); | ||
} | ||
} | ||
|
||
function neverResolve() { | ||
return new Promise(() => { | ||
// | ||
}); | ||
} | ||
|
||
const fns = [ | ||
neverResolve, | ||
neverResolve, | ||
neverResolve, | ||
neverResolve, | ||
neverResolve, | ||
longWork, // [5] | ||
neverResolve, | ||
neverResolve, | ||
neverResolve, | ||
neverResolve, | ||
]; | ||
|
||
for (let id = 0; id < 10; id++) { | ||
Sentry.withIsolationScope(async () => { | ||
Sentry.setUser({ id }); | ||
|
||
await fns[id](); | ||
}); | ||
} |
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 |
---|---|---|
|
@@ -17,6 +17,9 @@ Sentry.init({ | |
integrations: [anr], | ||
}); | ||
|
||
Sentry.setUser({ email: '[email protected]' }); | ||
Sentry.addBreadcrumb({ message: 'important message!' }); | ||
|
||
function longWorkIgnored() { | ||
for (let i = 0; i < 20; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
|
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 |
---|---|---|
|
@@ -21,6 +21,15 @@ const EXPECTED_ANR_EVENT = { | |
timezone: expect.any(String), | ||
}, | ||
}, | ||
user: { | ||
email: '[email protected]', | ||
}, | ||
breadcrumbs: [ | ||
{ | ||
timestamp: expect.any(Number), | ||
message: 'important message!', | ||
}, | ||
], | ||
// and an exception that is our ANR | ||
exception: { | ||
values: [ | ||
|
@@ -56,9 +65,59 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () => | |
cleanupChildProcesses(); | ||
}); | ||
|
||
const EXPECTED_LEGACY_ANR_EVENT = { | ||
// Ensure we have context | ||
contexts: { | ||
trace: { | ||
span_id: expect.any(String), | ||
trace_id: expect.any(String), | ||
}, | ||
device: { | ||
arch: expect.any(String), | ||
}, | ||
app: { | ||
app_start_time: expect.any(String), | ||
}, | ||
os: { | ||
name: expect.any(String), | ||
}, | ||
culture: { | ||
timezone: expect.any(String), | ||
}, | ||
}, | ||
// and an exception that is our ANR | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'ApplicationNotResponding', | ||
value: 'Application Not Responding for at least 100 ms', | ||
mechanism: { type: 'ANR' }, | ||
stacktrace: { | ||
frames: expect.arrayContaining([ | ||
{ | ||
colno: expect.any(Number), | ||
lineno: expect.any(Number), | ||
filename: expect.any(String), | ||
function: '?', | ||
in_app: true, | ||
}, | ||
{ | ||
colno: expect.any(Number), | ||
lineno: expect.any(Number), | ||
filename: expect.any(String), | ||
function: 'longWork', | ||
in_app: true, | ||
}, | ||
]), | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
// TODO (v8): Remove this old API and this test | ||
test('Legacy API', done => { | ||
createRunner(__dirname, 'legacy.js').expect({ event: EXPECTED_ANR_EVENT }).start(done); | ||
createRunner(__dirname, 'legacy.js').expect({ event: EXPECTED_LEGACY_ANR_EVENT }).start(done); | ||
}); | ||
|
||
test('CJS', done => { | ||
|
@@ -110,4 +169,34 @@ conditionalTest({ min: 16 })('should report ANR when event loop blocked', () => | |
test('worker can be stopped and restarted', done => { | ||
createRunner(__dirname, 'stop-and-start.js').expect({ event: EXPECTED_ANR_EVENT }).start(done); | ||
}); | ||
|
||
const EXPECTED_ISOLATED_EVENT = { | ||
user: { | ||
id: 5, | ||
}, | ||
exception: { | ||
values: [ | ||
{ | ||
type: 'ApplicationNotResponding', | ||
value: 'Application Not Responding for at least 100 ms', | ||
mechanism: { type: 'ANR' }, | ||
stacktrace: { | ||
frames: expect.arrayContaining([ | ||
{ | ||
colno: expect.any(Number), | ||
lineno: expect.any(Number), | ||
filename: expect.stringMatching(/isolated.mjs$/), | ||
function: 'longWork', | ||
in_app: true, | ||
}, | ||
]), | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
test('fetches correct isolated scope', done => { | ||
createRunner(__dirname, 'isolated.mjs').expect({ event: EXPECTED_ISOLATED_EVENT }).start(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
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