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 1 commit
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
13 changes: 13 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,17 @@ 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) {
if (sentryExceptionCache.has(tags.audit)) return;
sentryExceptionCache.set(tags.audit, true);
}

if (tags.gatherer) {
if (sentryExceptionCache.has(tags.gatherer)) return;
sentryExceptionCache.set(tags.gatherer, 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