From f276abf9e85d182f63b04d93040930c180ff7b77 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Wed, 8 May 2024 14:11:39 +0200 Subject: [PATCH] Condensed logic for determining whether to send Sentry events refs https://docs.sentry.io/platforms/javascript/configuration/filtering/#using--1%20 - this simplifies our logic to determine whether we should send events by moving the code to `beforeSend` - `errorHandler` is going away in Sentry v8 so this results in a shorter diff in the future - the logic should be the same, always send non-Ghost errors, and only send HTTP 500 Ghost errors --- ghost/core/core/shared/sentry.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/ghost/core/core/shared/sentry.js b/ghost/core/core/shared/sentry.js index 7bb7c73afd..6f777574b3 100644 --- a/ghost/core/core/shared/sentry.js +++ b/ghost/core/core/shared/sentry.js @@ -54,6 +54,14 @@ const beforeSend = function (event, hint) { event.tags.code = code; event.tags.id = id; event.tags.status_code = statusCode; + + // Only handle 500 errors for now + // This is because the only other 5XX error should be 503, which are deliberate maintenance/boot errors + if (statusCode === 500) { + return event; + } else { + return null; + } } return event; } catch (error) { @@ -140,19 +148,7 @@ if (sentryConfig && !sentryConfig.disabled) { module.exports = { requestHandler: Sentry.Handlers.requestHandler(), - errorHandler: Sentry.Handlers.errorHandler({ - shouldHandleError(error) { - // Sometimes non-Ghost issues will come into here but they won't - // have a statusCode so we should always handle them - if (!errors.utils.isGhostError(error)) { - return true; - } - - // Only handle 500 errors for now - // This is because the only other 5XX error should be 503, which are deliberate maintenance/boot errors - return (error.statusCode === 500); - } - }), + errorHandler: Sentry.Handlers.errorHandler(), tracingHandler: Sentry.Handlers.tracingHandler(), captureException: Sentry.captureException, captureMessage: Sentry.captureMessage,