From f658126780e97a4cd62031de9f28bd0f2bf3f4a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 21 Jun 2019 17:33:21 +0200 Subject: [PATCH 1/4] Support exception management with Airbrake+Errbit With Errbit, you can set up your own server and host the information regarding your exceptions there. You can also hire Airbrake's hosting services or easily setup Errbit on Heroku. We're still including the rollbar gem so we don't harm CONSUL users who are using rollbar. Note Errbit requires an old version of Airbrake which forced users to configure the gem. So we're adding the current environtment to `ignore_environments` when the project id isn't defined; this way the application won't crash in this case. --- Gemfile | 1 + Gemfile.lock | 4 ++++ config/initializers/errbit.rb | 9 +++++++++ config/secrets.yml.example | 12 ++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 config/initializers/errbit.rb diff --git a/Gemfile b/Gemfile index 5bd6a3a90..aa822d2d3 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem "rails", "5.1.7" gem "acts-as-taggable-on", "~> 6.5.0" gem "acts_as_votable", "~> 0.11.1" gem "ahoy_matey", "~> 1.6.0" +gem "airbrake", "~> 5.0" gem "ancestry", "~> 3.0.7" gem "audited", "~> 4.9.0" gem "autoprefixer-rails", "~> 8.2.0" diff --git a/Gemfile.lock b/Gemfile.lock index 3119a74bc..5e7df6b2e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -63,6 +63,9 @@ GEM safely_block (>= 0.1.1) user_agent_parser uuidtools + airbrake (5.8.1) + airbrake-ruby (~> 1.8) + airbrake-ruby (1.8.0) airbrussh (1.4.0) sshkit (>= 1.6.1, != 1.7.0) akami (1.3.1) @@ -622,6 +625,7 @@ DEPENDENCIES acts-as-taggable-on (~> 6.5.0) acts_as_votable (~> 0.11.1) ahoy_matey (~> 1.6.0) + airbrake (~> 5.0) ancestry (~> 3.0.7) audited (~> 4.9.0) autoprefixer-rails (~> 8.2.0) diff --git a/config/initializers/errbit.rb b/config/initializers/errbit.rb new file mode 100644 index 000000000..9e1ba059c --- /dev/null +++ b/config/initializers/errbit.rb @@ -0,0 +1,9 @@ +Airbrake.configure do |config| + config.host = Rails.application.secrets.errbit_host + config.project_id = Rails.application.secrets.errbit_project_id + config.project_key = Rails.application.secrets.errbit_project_key + + config.environment = Rails.env + config.ignore_environments = %w[development test] + config.ignore_environments += [Rails.env] if Rails.application.secrets.errbit_project_id.blank? +end diff --git a/config/secrets.yml.example b/config/secrets.yml.example index 6b81a6400..da94d81d7 100644 --- a/config/secrets.yml.example +++ b/config/secrets.yml.example @@ -43,6 +43,10 @@ staging: # :enable_starttls_auto: true force_ssl: true delay_jobs: true + errbit_host: "" + errbit_project_key: "" + errbit_project_id: 1 + errbit_self_hosted_ssl: false rollbar_server_token: "" http_basic_username: "" http_basic_password: "" @@ -66,6 +70,10 @@ preproduction: # :enable_starttls_auto: true force_ssl: true delay_jobs: true + errbit_host: "" + errbit_project_key: "" + errbit_project_id: 1 + errbit_self_hosted_ssl: false rollbar_server_token: "" http_basic_username: "" http_basic_password: "" @@ -94,6 +102,10 @@ production: # :enable_starttls_auto: true force_ssl: true delay_jobs: true + errbit_host: "" + errbit_project_key: "" + errbit_project_id: 1 + errbit_self_hosted_ssl: false rollbar_server_token: "" http_basic_username: "" http_basic_password: "" From 4ac36b91e278ea259be95b37912f699f12d47f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 21 Jun 2019 18:07:42 +0200 Subject: [PATCH 2/4] Accept self-signed SSL certificates with airbrake Since some people hosting errbit might be using it as an internal tool with a self signed certificate, we need to patch Airbrake so it accepts these certificates. --- config/initializers/errbit.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/config/initializers/errbit.rb b/config/initializers/errbit.rb index 9e1ba059c..3eb211bcc 100644 --- a/config/initializers/errbit.rb +++ b/config/initializers/errbit.rb @@ -7,3 +7,20 @@ Airbrake.configure do |config| config.ignore_environments = %w[development test] config.ignore_environments += [Rails.env] if Rails.application.secrets.errbit_project_id.blank? end + +if Rails.application.secrets.errbit_self_hosted_ssl.present? + # Patch from: https://mensfeld.pl/2016/05/setting-up-errbit-reporter-airbrake-v5-gem-to-work-with-self-signed-https-certificate/ + module Patches + module Airbrake + module SyncSender + def build_https(uri) + super.tap do |req| + req.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + end + end + end + end + + Airbrake::SyncSender.prepend(::Patches::Airbrake::SyncSender) +end From 83fb7a769c82000de47fe264b3449b1b00b4b0c4 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 23 Aug 2019 17:48:21 +0700 Subject: [PATCH 3/4] Ignore RecordNotFound exceptions in Errbit --- config/initializers/errbit.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/initializers/errbit.rb b/config/initializers/errbit.rb index 3eb211bcc..bb22b04ba 100644 --- a/config/initializers/errbit.rb +++ b/config/initializers/errbit.rb @@ -8,6 +8,11 @@ Airbrake.configure do |config| config.ignore_environments += [Rails.env] if Rails.application.secrets.errbit_project_id.blank? end +Airbrake.add_filter do |notice| + ignorables = %w[ActiveRecord::RecordNotFound] + notice.ignore! if ignorables.include? notice[:errors].first[:type] +end + if Rails.application.secrets.errbit_self_hosted_ssl.present? # Patch from: https://mensfeld.pl/2016/05/setting-up-errbit-reporter-airbrake-v5-gem-to-work-with-self-signed-https-certificate/ module Patches From 6db5e1ed55ef1e752abaa6534b975a9d537f4bb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Sun, 26 Apr 2020 13:34:57 +0200 Subject: [PATCH 4/4] Only enable rollbar if it's configured Many users who didn't configure rollbar were getting exceptions when trying to connect to the rollbar service. --- config/initializers/rollbar.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/initializers/rollbar.rb b/config/initializers/rollbar.rb index 95ebb341c..3c5ecec3c 100644 --- a/config/initializers/rollbar.rb +++ b/config/initializers/rollbar.rb @@ -7,7 +7,7 @@ Rollbar.configure do |config| # Here we'll disable all environments except 'staging', 'preproduction' and 'production': if Rails.env.staging? || Rails.env.preproduction? || Rails.env.production? - config.enabled = true + config.enabled = Rails.application.secrets.rollbar_server_token.present? else config.enabled = false end