Skip to content

Commit 118034c

Browse files
authored
feat: exclude insights from rake tasks config (#697)
This introduces a new configuration option `insights.exclude_rake_tasks`. By default this includes the `assets:precompile` rake task commonly executed in Rails. This can be overridden to include other tasks when needed.
1 parent 14ae485 commit 118034c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/honeybadger/config.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,18 @@ def load_plugin?(name)
289289
end
290290

291291
def insights_enabled?
292-
public? && !!self[:'insights.enabled']
292+
return false unless public?
293+
return false if insights_exclude_for_rake_tasks?
294+
!!self[:'insights.enabled']
295+
end
296+
297+
def insights_exclude_for_rake_tasks?
298+
return false unless defined?(Rake) && Rake.application&.top_level_tasks
299+
300+
current_tasks = Array(Rake.application.top_level_tasks)
301+
excluded_tasks = Array(self[:'insights.exclude_rake_tasks'])
302+
303+
(current_tasks & excluded_tasks).any?
293304
end
294305

295306
def cluster_collection?(name)

lib/honeybadger/config/defaults.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ class Boolean; end
497497
default: 60,
498498
type: Integer
499499
},
500+
:'insights.exclude_rake_tasks' => {
501+
description: "List of Rake tasks to exclude from Insights instrumentation.",
502+
default: ['assets:precompile'],
503+
type: Array
504+
},
500505
:'puma.insights.events' => {
501506
description: 'Enable automatic event capturing for Puma stats.',
502507
default: true,

0 commit comments

Comments
 (0)