Skip to content

Commit d899994

Browse files
committed
Add config options to control instrumentation
Add an instrument option for each background job framework and library that lacked one. Sidekiq, Shoryuken, Que, Resque, Delayed Job, Active Job, Excon and MongoDB can now each be turned off through instrument_<name>, matching the existing options for Faraday, http.rb, Net::HTTP, Redis and Sequel. Setting one to false makes the hook report its dependencies as absent, so the integration never installs. That turns off both the job or request instrumentation and the enqueue instrumentation for that framework. Add the enable_job_enqueue_instrumentation option. When it is false, job_enqueue_events_suppressed? reports true, which every enqueue integration already checks before recording its event. This reuses the existing enqueue suppression path, so one option turns the enqueue events off everywhere without touching how the jobs themselves are instrumented. The Active Job integration did not check that flag for its own event yet, so it now does, the same way the standalone adapters do.
1 parent caa8fbc commit d899994

23 files changed

Lines changed: 274 additions & 13 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
bump: minor
3+
type: add
4+
---
5+
6+
Add config options to turn individual integrations off. Set
7+
`instrument_sidekiq`, `instrument_shoryuken`, `instrument_que`,
8+
`instrument_resque`, `instrument_delayed_job`, `instrument_active_job`,
9+
`instrument_excon` or `instrument_mongo` to `false` to disable that
10+
integration entirely. This turns off both the instrumentation of the jobs or
11+
requests and the enqueue instrumentation for that integration. They all
12+
default to `true`. Each can also be set through its environment variable, such
13+
as `APPSIGNAL_INSTRUMENT_SIDEKIQ`.

lib/appsignal/config.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def dsl_config_file?
9696
:enable_at_exit_hook => "on_error",
9797
:enable_at_exit_reporter => true,
9898
:enable_host_metrics => true,
99+
:enable_job_enqueue_instrumentation => true,
99100
:enable_minutely_probes => true,
100101
:enable_statsd => true,
101102
:enable_nginx_metrics => false,
@@ -113,13 +114,21 @@ def dsl_config_file?
113114
:ignore_errors => [],
114115
:ignore_logs => [],
115116
:ignore_namespaces => [],
117+
:instrument_active_job => true,
116118
:instrument_code_ownership => true,
119+
:instrument_delayed_job => true,
120+
:instrument_excon => true,
117121
:instrument_faraday => true,
118122
:instrument_http_rb => true,
123+
:instrument_mongo => true,
119124
:instrument_net_http => true,
120125
:instrument_ownership => true,
126+
:instrument_que => true,
121127
:instrument_redis => true,
128+
:instrument_resque => true,
122129
:instrument_sequel => true,
130+
:instrument_shoryuken => true,
131+
:instrument_sidekiq => true,
123132
:log => "file",
124133
:logging_endpoint => "https://appsignal-endpoint.net",
125134
:ownership_set_namespace => false,
@@ -181,6 +190,8 @@ def dsl_config_file?
181190
:enable_allocation_tracking => "APPSIGNAL_ENABLE_ALLOCATION_TRACKING",
182191
:enable_at_exit_reporter => "APPSIGNAL_ENABLE_AT_EXIT_REPORTER",
183192
:enable_host_metrics => "APPSIGNAL_ENABLE_HOST_METRICS",
193+
:enable_job_enqueue_instrumentation =>
194+
"APPSIGNAL_ENABLE_JOB_ENQUEUE_INSTRUMENTATION",
184195
:enable_minutely_probes => "APPSIGNAL_ENABLE_MINUTELY_PROBES",
185196
:enable_statsd => "APPSIGNAL_ENABLE_STATSD",
186197
:enable_nginx_metrics => "APPSIGNAL_ENABLE_NGINX_METRICS",
@@ -192,13 +203,21 @@ def dsl_config_file?
192203
:enable_rake_performance_instrumentation =>
193204
"APPSIGNAL_ENABLE_RAKE_PERFORMANCE_INSTRUMENTATION",
194205
:files_world_accessible => "APPSIGNAL_FILES_WORLD_ACCESSIBLE",
206+
:instrument_active_job => "APPSIGNAL_INSTRUMENT_ACTIVE_JOB",
195207
:instrument_code_ownership => "APPSIGNAL_INSTRUMENT_CODE_OWNERSHIP",
208+
:instrument_delayed_job => "APPSIGNAL_INSTRUMENT_DELAYED_JOB",
209+
:instrument_excon => "APPSIGNAL_INSTRUMENT_EXCON",
196210
:instrument_faraday => "APPSIGNAL_INSTRUMENT_FARADAY",
197211
:instrument_http_rb => "APPSIGNAL_INSTRUMENT_HTTP_RB",
212+
:instrument_mongo => "APPSIGNAL_INSTRUMENT_MONGO",
198213
:instrument_net_http => "APPSIGNAL_INSTRUMENT_NET_HTTP",
199214
:instrument_ownership => "APPSIGNAL_INSTRUMENT_OWNERSHIP",
215+
:instrument_que => "APPSIGNAL_INSTRUMENT_QUE",
200216
:instrument_redis => "APPSIGNAL_INSTRUMENT_REDIS",
217+
:instrument_resque => "APPSIGNAL_INSTRUMENT_RESQUE",
201218
:instrument_sequel => "APPSIGNAL_INSTRUMENT_SEQUEL",
219+
:instrument_shoryuken => "APPSIGNAL_INSTRUMENT_SHORYUKEN",
220+
:instrument_sidekiq => "APPSIGNAL_INSTRUMENT_SIDEKIQ",
202221
:ownership_set_namespace => "APPSIGNAL_OWNERSHIP_SET_NAMESPACE",
203222
:running_in_container => "APPSIGNAL_RUNNING_IN_CONTAINER",
204223
:send_environment_metadata => "APPSIGNAL_SEND_ENVIRONMENT_METADATA",
@@ -828,6 +847,8 @@ def activate_if_environment(*envs)
828847
# @return [Boolean] Configure whether the at_exit reporter is enabled
829848
# @!attribute [rw] enable_host_metrics
830849
# @return [Boolean] Configure whether host metrics collection is enabled
850+
# @!attribute [rw] enable_job_enqueue_instrumentation
851+
# @return [Boolean] Configure whether to record an event when a background job is enqueued
831852
# @!attribute [rw] enable_minutely_probes
832853
# @return [Boolean] Configure whether minutely probes are enabled
833854
# @!attribute [rw] enable_statsd
@@ -846,18 +867,34 @@ def activate_if_environment(*envs)
846867
# @return [Boolean] Configure whether Rake performance instrumentation is enabled
847868
# @!attribute [rw] files_world_accessible
848869
# @return [Boolean] Configure whether files created by AppSignal should be world accessible
870+
# @!attribute [rw] instrument_active_job
871+
# @return [Boolean] Configure whether to instrument Active Job
872+
# @!attribute [rw] instrument_delayed_job
873+
# @return [Boolean] Configure whether to instrument Delayed Job
874+
# @!attribute [rw] instrument_excon
875+
# @return [Boolean] Configure whether to instrument requests made with the Excon gem
849876
# @!attribute [rw] instrument_faraday
850877
# @return [Boolean] Configure whether to instrument requests made with the Faraday gem
851878
# @!attribute [rw] instrument_http_rb
852879
# @return [Boolean] Configure whether to instrument requests made with the http.rb gem
880+
# @!attribute [rw] instrument_mongo
881+
# @return [Boolean] Configure whether to instrument MongoDB queries
853882
# @!attribute [rw] instrument_net_http
854883
# @return [Boolean] Configure whether to instrument requests made with Net::HTTP
855884
# @!attribute [rw] instrument_ownership
856885
# @return [Boolean] Configure whether to instrument the Ownership gem
886+
# @!attribute [rw] instrument_que
887+
# @return [Boolean] Configure whether to instrument Que
857888
# @!attribute [rw] instrument_redis
858889
# @return [Boolean] Configure whether to instrument Redis queries
890+
# @!attribute [rw] instrument_resque
891+
# @return [Boolean] Configure whether to instrument Resque
859892
# @!attribute [rw] instrument_sequel
860893
# @return [Boolean] Configure whether to instrument Sequel queries
894+
# @!attribute [rw] instrument_shoryuken
895+
# @return [Boolean] Configure whether to instrument Shoryuken
896+
# @!attribute [rw] instrument_sidekiq
897+
# @return [Boolean] Configure whether to instrument Sidekiq
861898
# @!attribute [rw] ownership_set_namespace
862899
# @return [Boolean] Configure whether the Ownership gem instrumentation should set namespace
863900
# @!attribute [rw] running_in_container

lib/appsignal/hooks/active_job.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def self.dependencies_present?
2222
end
2323

2424
def dependencies_present?
25-
self.class.dependencies_present?
25+
self.class.dependencies_present? && Appsignal.config &&
26+
Appsignal.config[:instrument_active_job]
2627
end
2728

2829
def install
@@ -56,6 +57,15 @@ def install
5657
# @!visibility private
5758
module ActiveJobEnqueueInstrumentation
5859
def enqueue(*, **)
60+
# Skip recording the event when enqueue events are suppressed. That is
61+
# the case when enqueue instrumentation is disabled, and it keeps this
62+
# integration consistent with the standalone adapters (Sidekiq, ...),
63+
# which already gate their own enqueue event on this check.
64+
if Appsignal::Transaction.current? &&
65+
Appsignal::Transaction.current.job_enqueue_events_suppressed?
66+
return super
67+
end
68+
5969
Appsignal.instrument("enqueue.active_job", "enqueue #{self.class.name} job") do
6070
# Active Job enqueues through an adapter (Sidekiq, Resque, ...) that
6171
# has its own enqueue instrumentation. Suppress it so the enqueue is

lib/appsignal/hooks/delayed_job.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class DelayedJobHook < Appsignal::Hooks::Hook
77
register :delayed_job
88

99
def dependencies_present?
10-
defined?(::Delayed::Plugin)
10+
defined?(::Delayed::Plugin) && Appsignal.config &&
11+
Appsignal.config[:instrument_delayed_job]
1112
end
1213

1314
def install

lib/appsignal/hooks/excon.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ExconHook < Appsignal::Hooks::Hook
77
register :excon
88

99
def dependencies_present?
10-
Appsignal.config && defined?(::Excon)
10+
Appsignal.config && defined?(::Excon) && Appsignal.config[:instrument_excon]
1111
end
1212

1313
def install

lib/appsignal/hooks/mongo_ruby_driver.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class MongoRubyDriverHook < Appsignal::Hooks::Hook
77
register :mongo_ruby_driver
88

99
def dependencies_present?
10-
defined?(::Mongo::Monitoring::Global)
10+
defined?(::Mongo::Monitoring::Global) && Appsignal.config &&
11+
Appsignal.config[:instrument_mongo]
1112
end
1213

1314
def install

lib/appsignal/hooks/que.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class QueHook < Appsignal::Hooks::Hook
77
register :que
88

99
def dependencies_present?
10-
defined?(::Que::Job)
10+
defined?(::Que::Job) && Appsignal.config && Appsignal.config[:instrument_que]
1111
end
1212

1313
def install

lib/appsignal/hooks/resque.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ResqueHook < Appsignal::Hooks::Hook
77
register :resque
88

99
def dependencies_present?
10-
defined?(::Resque)
10+
defined?(::Resque) && Appsignal.config && Appsignal.config[:instrument_resque]
1111
end
1212

1313
def install

lib/appsignal/hooks/shoryuken.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ShoryukenHook < Appsignal::Hooks::Hook
77
register :shoryuken
88

99
def dependencies_present?
10-
defined?(::Shoryuken)
10+
defined?(::Shoryuken) && Appsignal.config && Appsignal.config[:instrument_shoryuken]
1111
end
1212

1313
def install

lib/appsignal/hooks/sidekiq.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def self.dependencies_present?
2020
end
2121

2222
def dependencies_present?
23-
self.class.dependencies_present?
23+
self.class.dependencies_present? && Appsignal.config &&
24+
Appsignal.config[:instrument_sidekiq]
2425
end
2526

2627
def install

0 commit comments

Comments
 (0)