зеркало из https://github.com/mozilla/fxa.git
bug(auth): Fix issue where errors are being reported that should be repressed.
Because: - After adding tracing and upgrading sentry it appears errors can propagate in other ways. This Commit: - Moves the ignoreError check into the error module - Runs the ignoreError check in the filterEvents function that runs on before send.
This commit is contained in:
Родитель
1e50382016
Коммит
65095d40ec
|
@ -1594,5 +1594,47 @@ function appErrorFromOauthError(err) {
|
|||
}
|
||||
}
|
||||
|
||||
// Maintain list of errors that should not be sent to Sentry
|
||||
const IGNORED_ERROR_NUMBERS = [
|
||||
ERRNO.BOUNCE_HARD,
|
||||
ERRNO.BOUNCE_SOFT,
|
||||
ERRNO.BOUNCE_COMPLAINT,
|
||||
];
|
||||
|
||||
/**
|
||||
* Prevents errors from being captured in sentry.
|
||||
*
|
||||
* @param {Error} error An error with an error number. Note that errors of type vError will
|
||||
* use the underlying jse_cause error if possible.
|
||||
*/
|
||||
function ignoreErrors(error) {
|
||||
if (!error) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prefer jse_cause, but fallback to top level error if needed
|
||||
const statusCode =
|
||||
determineStatusCode(error.jse_cause) || determineStatusCode(error);
|
||||
|
||||
const errno = error.jse_cause?.errno || error.errno;
|
||||
|
||||
// Ignore non 500 status codes and specific error numbers
|
||||
return statusCode < 500 || IGNORED_ERROR_NUMBERS.includes(errno);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an error tries to determine the HTTP status code associated with the error.
|
||||
* @param {*} error
|
||||
* @returns
|
||||
*/
|
||||
function determineStatusCode(error) {
|
||||
if (!error) {
|
||||
return;
|
||||
}
|
||||
|
||||
return error.statusCode || error.output?.statusCode || error.code;
|
||||
}
|
||||
|
||||
module.exports = AppError;
|
||||
module.exports.ERRNO = ERRNO;
|
||||
module.exports.ignoreErrors = ignoreErrors;
|
||||
|
|
|
@ -10,6 +10,7 @@ const logger = require('./log')(
|
|||
'configure-sentry'
|
||||
);
|
||||
const { version } = require('../package.json');
|
||||
const { ignoreErrors } = require('./error');
|
||||
|
||||
/**
|
||||
* Initialize sentry & otel
|
||||
|
@ -40,6 +41,14 @@ const URIENCODEDFILTERED = encodeURIComponent(FILTERED);
|
|||
* @param {Sentry.Event} event
|
||||
*/
|
||||
function filterSentryEvent(event, hint) {
|
||||
// If we encounter a WError, we likely want to filter it out. These errors are
|
||||
// intentionally relayed to the client, and don't constitute unexpected errors.
|
||||
// Note, that these might arrive here from our reportSentryError function, or
|
||||
// some other instrumentation that has captured the error.
|
||||
if (hint?.originalException != null && ignoreErrors(hint.originalException)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (event.breadcrumbs) {
|
||||
for (const bc of event.breadcrumbs) {
|
||||
if (bc.message) {
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
const Hoek = require('@hapi/hoek');
|
||||
const Sentry = require('@sentry/node');
|
||||
const verror = require('verror');
|
||||
const { ERRNO } = require('./error');
|
||||
const { ignoreErrors } = require('./error');
|
||||
|
||||
const {
|
||||
formatMetadataValidationErrorMessage,
|
||||
reportValidationError,
|
||||
|
@ -17,13 +18,6 @@ const {
|
|||
const TOKENREGEX = /[a-fA-F0-9]{32,}/gi;
|
||||
const FILTERED = '[Filtered]';
|
||||
|
||||
// Maintain list of errors that should not be sent to Sentry
|
||||
const IGNORED_ERROR_NUMBERS = [
|
||||
ERRNO.BOUNCE_HARD,
|
||||
ERRNO.BOUNCE_SOFT,
|
||||
ERRNO.BOUNCE_COMPLAINT,
|
||||
];
|
||||
|
||||
function reportSentryError(err, request) {
|
||||
let exception = '';
|
||||
if (err && err.stack) {
|
||||
|
@ -149,40 +143,6 @@ async function configureSentry(server, config, processName = 'key_server') {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents errors from being captured in sentry.
|
||||
*
|
||||
* @param {Error} error An error with an error number. Note that errors of type vError will
|
||||
* use the underlying jse_cause error if possible.
|
||||
*/
|
||||
function ignoreErrors(error) {
|
||||
if (!error) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prefer jse_cause, but fallback to top level error if needed
|
||||
const statusCode =
|
||||
determineStatusCode(error.jse_cause) || determineStatusCode(error);
|
||||
|
||||
const errno = error.jse_cause?.errno || error.errno;
|
||||
|
||||
// Ignore non 500 status codes and specific error numbers
|
||||
return statusCode < 500 || IGNORED_ERROR_NUMBERS.includes(errno);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an error tries to determine the HTTP status code associated with the error.
|
||||
* @param {*} error
|
||||
* @returns
|
||||
*/
|
||||
function determineStatusCode(error) {
|
||||
if (!error) {
|
||||
return;
|
||||
}
|
||||
|
||||
return error.statusCode || error.output?.statusCode || error.code;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
configureSentry,
|
||||
reportSentryError,
|
||||
|
|
Загрузка…
Ссылка в новой задаче