-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
misc: only allow 1 error from each audit/gatherer #6215
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,8 @@ function init(opts) { | |
sentryDelegate.captureBreadcrumb = (...args) => Sentry.captureBreadcrumb(...args); | ||
sentryDelegate.getContext = () => Sentry.getContext(); | ||
|
||
// Keep a record of exceptions per audit/gatherer so we can just report once | ||
const sentryExceptionCache = new Map(); | ||
// Special case captureException to return a Promise so we don't process.exit too early | ||
sentryDelegate.captureException = async (err, opts = {}) => { | ||
// Ignore if there wasn't an error | ||
|
@@ -74,6 +76,19 @@ function init(opts) { | |
// @ts-ignore Non-standard property added to flag error as not needing capturing. | ||
if (err.expected) return; | ||
|
||
const tags = opts.tags || {}; | ||
if (tags.audit) { | ||
const key = `audit-${tags.audit}-${err.message}`; | ||
if (sentryExceptionCache.has(key)) return; | ||
sentryExceptionCache.set(key, true); | ||
} | ||
|
||
if (tags.gatherer) { | ||
const key = `gatherer-${tags.gatherer}-${err.message}`; | ||
if (sentryExceptionCache.has(key)) return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it has the key we want to |
||
sentryExceptionCache.set(key, true); | ||
} | ||
|
||
// Sample known errors that occur at a high frequency. | ||
const sampledErrorMatch = SAMPLED_ERRORS.find(sample => sample.pattern.test(err.message)); | ||
if (sampledErrorMatch && sampledErrorMatch.rate <= Math.random()) return; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: Could 1 exception have both audit and gatherer tags? In which case returning here would not allow the gatherer tags to be analyzed? I don't think so, but wanted to make sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, it either happens in an audit, or a gatherer, or neither :)