Skip to content
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

Merged
merged 2 commits into from
Oct 17, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lighthouse-core/lib/sentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Copy link
Member

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.

Copy link
Collaborator Author

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 :)

sentryExceptionCache.set(key, true);
}

if (tags.gatherer) {
const key = `gatherer-${tags.gatherer}-${err.message}`;
if (sentryExceptionCache.has(key)) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why check has? Can't it just set it and override the old version in the map? Or is that not readable JS? 😕

Copy link
Collaborator Author

@patrickhulce patrickhulce Oct 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it has the key we want to return and skip the rest of function execution, not just the rest of the block. worth adding a comment since it's confusing already? :)

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;
Expand Down