0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00

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
This commit is contained in:
Daniel Lockyer 2024-05-08 14:11:39 +02:00 committed by Daniel Lockyer
parent 77fc66340a
commit f276abf9e8

View file

@ -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,