Skip to content

Commit

Permalink
refactor: adjusted internal error instrumentation
Browse files Browse the repository at this point in the history
 Wrapped the Internal Error Instrumentation in an `unless` block to ensure the application does not report internal errors to the Prometheus metrics when the error is a 404 or 422 thereby reducing the noise in the Slack alerts channel
  • Loading branch information
jonrandahl committed Oct 9, 2024
1 parent fc9c5b6 commit dc98256
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ def log_request_result
# or attempt to render a generic error page if no specific error page exists
unless Rails.application.config.consider_all_requests_local
rescue_from StandardError do |e|
# Instrument ActiveSupport::Notifications for internal errors:
ActiveSupport::Notifications.instrument('internal_error.application', exception: e)
# Instrument ActiveSupport::Notifications for internal errors but only for non-404 errors:
unless e.is_a?(ActionController::RoutingError) || e.is_a?(ActionView::MissingTemplate)
ActiveSupport::Notifications.instrument('internal_error.application', exception: e)
end
# Trigger the appropriate error handling method based on the exception
case e.class
when ActionController::RoutingError, ActionView::MissingTemplate
Expand Down Expand Up @@ -104,7 +106,7 @@ def detailed_request_log(duration)
body: request.body.gets&.gsub("\n", '\n'),
method: request.method,
status: response.status,
message: Rack::Utils::HTTP_STATUS_CODES[response.status]
message: response.message || Rack::Utils::HTTP_STATUS_CODES[response.status]
}

case response.status
Expand Down

0 comments on commit dc98256

Please sign in to comment.