Skip to content

Commit

Permalink
fix: do not check for rails console (#574)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
roelbondoc authored Jul 1, 2024
1 parent 40d4a79 commit ba74af8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 0 additions & 1 deletion lib/honeybadger/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 10 additions & 8 deletions lib/honeybadger/plugins/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba74af8

Please sign in to comment.