docbrown/config/initializers/honeybadger.rb
Jacob Herrington a5b2d109d5
Rename banned and comment_banned roles (#12270)
* Rename banned and comment_banned roles

* Add data update script to rename roles containing 'ban'

* Add named error for Suspended users

* Update unidiomatic method names

* Rename misc banned to suspended

* Apply suggestions from code review

Co-authored-by: Michael Kohl <me@citizen428.net>

* Add unit tests for suspended methods

This commit also adds TODO comments for removing banned and
comment_banned from the codebase after data update scripts have
successfully run on all of our Forems.

Co-authored-by: Michael Kohl <me@citizen428.net>
2021-04-06 10:12:14 -05:00

54 lines
2.3 KiB
Ruby

# Can be used to implement more programatic error handling
# https://docs.honeybadger.io/lib/ruby/getting-started/ignoring-errors.html#ignore-programmatically
MESSAGE_FINGERPRINTS = {
"SuspendedError" => "banned",
"Rack::Timeout::RequestTimeoutException" => "rack_timeout",
"Rack::Timeout::RequestTimeoutError" => "rack_timeout",
"PG::QueryCanceled" => "pg_query_canceled"
}.freeze
COMPONENT_FINGERPRINTS = {
"internal" => "internal"
}.freeze
HONEYBADGER_EXCEPTIONS_TO_IGNORE = [
ActiveRecord::QueryCanceled,
ActiveRecord::RecordNotFound,
Pundit::NotAuthorizedError,
RateLimitChecker::LimitReached,
].freeze
Rails.application.reloader.to_prepare do
# https://docs.honeybadger.io/lib/ruby/gem-reference/configuration.html
Honeybadger.configure do |config|
config.env = "#{ApplicationConfig['APP_DOMAIN']}-#{Rails.env}"
config.api_key = ApplicationConfig["HONEYBADGER_API_KEY"]
config.revision = ApplicationConfig["RELEASE_FOOTPRINT"]
# Prevent Ruby from exiting until all queued notices have been delivered to Honeybadger.
# When set to true(default), it can lead to a large number of errors causing a process to get stuck.
# To prevent this we set it to false ensuring that a process can exit quickly regardless of errors.
# Logging allows us to fill in gaps if we need to when errors get discarded.
config.send_data_at_exit = false
config.exceptions.ignore += HONEYBADGER_EXCEPTIONS_TO_IGNORE
config.request.filter_keys += %w[authorization]
config.sidekiq.attempt_threshold = 10
config.breadcrumbs.enabled = true
config.before_notify do |notice|
notice.fingerprint = if notice.error_message&.include?("SIGTERM") && notice.component&.include?("feeds_import")
notice.error_message
elsif (msg_key = MESSAGE_FINGERPRINTS.keys.detect do |k, _v|
notice.error_message&.include?(k)
end)
MESSAGE_FINGERPRINTS[msg_key]
elsif (cmp_key = COMPONENT_FINGERPRINTS.keys.detect do |k, _v|
notice.component&.include?(k)
end)
COMPONENT_FINGERPRINTS[cmp_key]
end
end
end
end