-
-
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): Rework ANR to use worker script via an integration (#9823)
This PR reworks Node ANR detection to use a worker thread. Workers are usually started via a path to a source file but this can cause issues when bundlers are used. Instead, the worker code is bundled and included in the source as a base64 string which can be used to launch a worker via a data URL. The base64 code comes in at around 45KB. Positives 👍 - No extra processes - Only 10-15MB memory overhead (vs at least 50MB for a child process) - Uses inspector API so we can remove the websockets implementation - Doesn't require special cases/setup for Electron main process - No longer runs the app entry point again as the child process code - Closes some outstanding Electron ANR issues - ANR becomes just an integration since we don't need to intercept app execution in the child - Less confusing setup and less chance of running the app twice Negatives 👎 - Minimum supported Node version for ANR detection becomes v16 because Node 14 does not support data URLs for workers 😢 ## Usage ```ts import * as Sentry from '@sentry/node'; Sentry.init({ dsn: 'https://[email protected]/1337', integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })], }); ```
- Loading branch information
Showing
25 changed files
with
602 additions
and
894 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
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
29 changes: 13 additions & 16 deletions
29
packages/node-integration-tests/suites/anr/basic-session.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 |
---|---|---|
@@ -1,31 +1,28 @@ | ||
const crypto = require('crypto'); | ||
const assert = require('assert'); | ||
|
||
const Sentry = require('@sentry/node'); | ||
|
||
const { transport } = require('./test-transport.js'); | ||
|
||
// close both processes after 5 seconds | ||
setTimeout(() => { | ||
process.exit(); | ||
}, 5000); | ||
}, 10000); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
debug: true, | ||
transport, | ||
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })], | ||
}); | ||
|
||
Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 }).then(() => { | ||
function longWork() { | ||
for (let i = 0; i < 100; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
// eslint-disable-next-line no-unused-vars | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
} | ||
function longWork() { | ||
for (let i = 0; i < 100; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
// eslint-disable-next-line no-unused-vars | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
assert.ok(hash); | ||
} | ||
} | ||
|
||
setTimeout(() => { | ||
longWork(); | ||
}, 1000); | ||
}); | ||
setTimeout(() => { | ||
longWork(); | ||
}, 1000); |
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 |
---|---|---|
@@ -1,32 +1,29 @@ | ||
const crypto = require('crypto'); | ||
const assert = require('assert'); | ||
|
||
const Sentry = require('@sentry/node'); | ||
|
||
const { transport } = require('./test-transport.js'); | ||
|
||
// close both processes after 5 seconds | ||
setTimeout(() => { | ||
process.exit(); | ||
}, 5000); | ||
}, 10000); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
debug: true, | ||
autoSessionTracking: false, | ||
transport, | ||
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })], | ||
}); | ||
|
||
Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 }).then(() => { | ||
function longWork() { | ||
for (let i = 0; i < 100; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
// eslint-disable-next-line no-unused-vars | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
} | ||
function longWork() { | ||
for (let i = 0; i < 100; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
// eslint-disable-next-line no-unused-vars | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
assert.ok(hash); | ||
} | ||
} | ||
|
||
setTimeout(() => { | ||
longWork(); | ||
}, 1000); | ||
}); | ||
setTimeout(() => { | ||
longWork(); | ||
}, 1000); |
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 |
---|---|---|
@@ -1,29 +1,26 @@ | ||
import * as assert from 'assert'; | ||
import * as crypto from 'crypto'; | ||
|
||
import * as Sentry from '@sentry/node'; | ||
|
||
const { transport } = await import('./test-transport.js'); | ||
|
||
// close both processes after 5 seconds | ||
setTimeout(() => { | ||
process.exit(); | ||
}, 5000); | ||
}, 10000); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
debug: true, | ||
autoSessionTracking: false, | ||
transport, | ||
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })], | ||
}); | ||
|
||
await Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 }); | ||
|
||
function longWork() { | ||
for (let i = 0; i < 100; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
// eslint-disable-next-line no-unused-vars | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
assert.ok(hash); | ||
} | ||
} | ||
|
||
|
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 |
---|---|---|
@@ -1,32 +1,29 @@ | ||
const crypto = require('crypto'); | ||
const assert = require('assert'); | ||
|
||
const Sentry = require('@sentry/node'); | ||
|
||
const { transport } = require('./test-transport.js'); | ||
|
||
// close both processes after 5 seconds | ||
setTimeout(() => { | ||
process.exit(); | ||
}, 5000); | ||
}, 10000); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
debug: true, | ||
autoSessionTracking: false, | ||
transport, | ||
integrations: [new Sentry.Integrations.Anr({ captureStackTrace: true, anrThreshold: 200 })], | ||
}); | ||
|
||
Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 }).then(() => { | ||
function longWork() { | ||
for (let i = 0; i < 100; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
// eslint-disable-next-line no-unused-vars | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
} | ||
function longWork() { | ||
for (let i = 0; i < 100; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
// eslint-disable-next-line no-unused-vars | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
assert.ok(hash); | ||
} | ||
} | ||
|
||
setTimeout(() => { | ||
longWork(); | ||
}, 1000); | ||
}); | ||
setTimeout(() => { | ||
longWork(); | ||
}, 1000); |
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,31 @@ | ||
const crypto = require('crypto'); | ||
const assert = require('assert'); | ||
|
||
const Sentry = require('@sentry/node'); | ||
|
||
setTimeout(() => { | ||
process.exit(); | ||
}, 10000); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
release: '1.0', | ||
debug: true, | ||
autoSessionTracking: false, | ||
}); | ||
|
||
// eslint-disable-next-line deprecation/deprecation | ||
Sentry.enableAnrDetection({ captureStackTrace: true, anrThreshold: 200 }).then(() => { | ||
function longWork() { | ||
for (let i = 0; i < 100; i++) { | ||
const salt = crypto.randomBytes(128).toString('base64'); | ||
// eslint-disable-next-line no-unused-vars | ||
const hash = crypto.pbkdf2Sync('myPassword', salt, 10000, 512, 'sha512'); | ||
assert.ok(hash); | ||
} | ||
} | ||
|
||
setTimeout(() => { | ||
longWork(); | ||
}, 1000); | ||
}); |
17 changes: 0 additions & 17 deletions
17
packages/node-integration-tests/suites/anr/test-transport.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.