From ba74af8b55393ea0a96962085ea48c4376380be3 Mon Sep 17 00:00:00 2001 From: Roel Bondoc Date: Mon, 1 Jul 2024 12:59:01 -0400 Subject: [PATCH] fix: do not check for rails console (#574) Some Rails applications may have Rails::Console defined (possibly through gems). This would inadvertantly disable Insights in production. The issue with this is that this will enable Insights in legitimate consoles, so we'll need to document how to disable it via ENV variables perhaps. --- lib/honeybadger/config.rb | 1 - lib/honeybadger/plugins/rails.rb | 18 ++++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/honeybadger/config.rb b/lib/honeybadger/config.rb index 471a61c3..711d7ca2 100644 --- a/lib/honeybadger/config.rb +++ b/lib/honeybadger/config.rb @@ -277,7 +277,6 @@ def load_plugin?(name) end def insights_enabled? - return false if defined?(::Rails.application) && ::Rails.const_defined?("Console") !!self[:'insights.enabled'] end diff --git a/lib/honeybadger/plugins/rails.rb b/lib/honeybadger/plugins/rails.rb index 13854e16..5e492dcd 100644 --- a/lib/honeybadger/plugins/rails.rb +++ b/lib/honeybadger/plugins/rails.rb @@ -71,16 +71,18 @@ def self.source_ignored?(source) end Plugin.register :rails do - requirement { config.load_plugin_insights?(:rails_metrics) && defined?(::Rails.application) && ::Rails.application } + requirement { defined?(::Rails.application) && ::Rails.application } execution do - ::ActiveSupport::Notifications.subscribe(/(process_action|send_file|redirect_to|halted_callback|unpermitted_parameters)\.action_controller/, Honeybadger::ActionControllerSubscriber.new) - ::ActiveSupport::Notifications.subscribe(/(write_fragment|read_fragment|expire_fragment|exist_fragment\?)\.action_controller/, Honeybadger::ActionControllerCacheSubscriber.new) - ::ActiveSupport::Notifications.subscribe(/cache_(read|read_multi|generate|fetch_hit|write|write_multi|increment|decrement|delete|delete_multi|cleanup|prune|exist\?)\.active_support/, Honeybadger::ActiveSupportCacheSubscriber.new) - ::ActiveSupport::Notifications.subscribe(/^render_(template|partial|collection)\.action_view/, Honeybadger::ActionViewSubscriber.new) - ::ActiveSupport::Notifications.subscribe("sql.active_record", Honeybadger::ActiveRecordSubscriber.new) - ::ActiveSupport::Notifications.subscribe("process.action_mailer", Honeybadger::ActionMailerSubscriber.new) - ::ActiveSupport::Notifications.subscribe(/(service_upload|service_download)\.active_storage/, Honeybadger::ActiveStorageSubscriber.new) + if config.load_plugin_insights?(:rails) + ::ActiveSupport::Notifications.subscribe(/(process_action|send_file|redirect_to|halted_callback|unpermitted_parameters)\.action_controller/, Honeybadger::ActionControllerSubscriber.new) + ::ActiveSupport::Notifications.subscribe(/(write_fragment|read_fragment|expire_fragment|exist_fragment\?)\.action_controller/, Honeybadger::ActionControllerCacheSubscriber.new) + ::ActiveSupport::Notifications.subscribe(/cache_(read|read_multi|generate|fetch_hit|write|write_multi|increment|decrement|delete|delete_multi|cleanup|prune|exist\?)\.active_support/, Honeybadger::ActiveSupportCacheSubscriber.new) + ::ActiveSupport::Notifications.subscribe(/^render_(template|partial|collection)\.action_view/, Honeybadger::ActionViewSubscriber.new) + ::ActiveSupport::Notifications.subscribe("sql.active_record", Honeybadger::ActiveRecordSubscriber.new) + ::ActiveSupport::Notifications.subscribe("process.action_mailer", Honeybadger::ActionMailerSubscriber.new) + ::ActiveSupport::Notifications.subscribe(/(service_upload|service_download)\.active_storage/, Honeybadger::ActiveStorageSubscriber.new) + end end end end