From 25e985cfce73f5b41596cfa614f6eaec7038d27e Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Thu, 23 Jan 2020 17:54:46 -0500 Subject: [PATCH] Group all PG::TRDeadlockDetected and PG::QueryCanceled errors together (#5681) [deploy] --- config/initializers/honeybadger.rb | 20 ++++++++++++++------ spec/initializers/honeybadger_spec.rb | 12 +++++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/config/initializers/honeybadger.rb b/config/initializers/honeybadger.rb index 36aa443de..9b707a647 100644 --- a/config/initializers/honeybadger.rb +++ b/config/initializers/honeybadger.rb @@ -1,6 +1,16 @@ # Can be used to implement more programatic error handling # https://docs.honeybadger.io/lib/ruby/getting-started/ignoring-errors.html#ignore-programmatically +MESSAGE_FINGERPRINTS = { + "BANNED" => "banned", + "Rack::Timeout::RequestTimeoutException" => "rack_timeout", + "PG::QueryCanceled" => "pg_query_canceled" +}.freeze + +COMPONENT_FINGERPRINTS = { + "internal" => "internal" +}.freeze + Honeybadger.configure do |config| config.api_key = ApplicationConfig["HONEYBADGER_API_KEY"] config.revision = ApplicationConfig["HEROKU_SLUG_COMMIT"] @@ -16,12 +26,10 @@ Honeybadger.configure do |config| config.before_notify do |notice| notice.fingerprint = if notice.error_message&.include?("SIGTERM") && notice.component&.include?("fetch_all_rss") notice.error_message - elsif notice.error_message&.include?("BANNED") - "banned" - elsif notice.error_message&.include?("Rack::Timeout::RequestTimeoutException") - "rack_timeout" - elsif notice.component&.include?("internal") - "internal" + elsif (msg_key = MESSAGE_FINGERPRINTS.keys.detect { |k, _v| notice.error_message&.include?(k) }) + MESSAGE_FINGERPRINTS[msg_key] + elsif (cmp_key = COMPONENT_FINGERPRINTS.keys.detect { |k, _v| notice.component&.include?(k) }) + COMPONENT_FINGERPRINTS[cmp_key] end end end diff --git a/spec/initializers/honeybadger_spec.rb b/spec/initializers/honeybadger_spec.rb index cab49aa26..0d780bf10 100644 --- a/spec/initializers/honeybadger_spec.rb +++ b/spec/initializers/honeybadger_spec.rb @@ -32,7 +32,7 @@ describe Honeybadger do end context "when error is raised from an internal route" do - it "halts notification" do + it "sets fingerprint to internal" do notice = Honeybadger::Notice.new( described_class.config, component: "internal/feedback_messages" ) @@ -40,4 +40,14 @@ describe Honeybadger do expect(notice.fingerprint).to eq("internal") end end + + context "when a PG::QueryCanceled error is raised" do + it "sets fingerprint to pg_query_cancel" do + notice = Honeybadger::Notice.new( + described_class.config, error_message: "ActionView::Template::Error: PG::QueryCanceled:" + ) + described_class.config.before_notify_hooks.first.call(notice) + expect(notice.fingerprint).to eq("pg_query_canceled") + end + end end