Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .changesets/add-delayed-job-enqueue-instrumentation.md

This file was deleted.

13 changes: 13 additions & 0 deletions .changesets/add-instrument-config-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
bump: minor
type: add
---

Add config options to turn individual integrations off. Set
`instrument_sidekiq`, `instrument_shoryuken`, `instrument_que`,
`instrument_resque`, `instrument_delayed_job`, `instrument_active_job`,
`instrument_excon` or `instrument_mongo` to `false` to disable that
integration entirely. This turns off both the instrumentation of the jobs or
requests and the enqueue instrumentation for that integration. They all
default to `true`. Each can also be set through its environment variable, such
as `APPSIGNAL_INSTRUMENT_SIDEKIQ`.
8 changes: 0 additions & 8 deletions .changesets/add-shoryuken-enqueue-instrumentation.md

This file was deleted.

6 changes: 0 additions & 6 deletions .changesets/emit-mongodb-body-as-json-string.md

This file was deleted.

10 changes: 0 additions & 10 deletions .changesets/instrument-active-job-enqueues.md

This file was deleted.

24 changes: 24 additions & 0 deletions .changesets/instrument-background-job-enqueues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
bump: minor
type: add
---

Instrument background job enqueues. Enqueuing a job now records an enqueue
event on the active transaction, so enqueues made from within a web request or
another job show up in the event timeline. This is recorded for Sidekiq
(`enqueue.sidekiq`), Que (`enqueue.que`, plus `bulk_enqueue.que` for bulk
enqueues on Que 2), Resque (`enqueue.resque`), Shoryuken (`enqueue.shoryuken`)
and Delayed Job (`enqueue.delayed_job`). Each event is titled after the job
being enqueued.

For Active Job, the `enqueue.active_job` event is now recorded by AppSignal's
own instrumentation rather than by Rails' native `enqueue.active_job`
notification. The native notification is suppressed so the enqueue is recorded
once, and the event is now titled after the job being enqueued.

These enqueue events can be turned off with the
`enable_job_enqueue_instrumentation` config option. Set it to `false` to stop
recording enqueue events across all integrations, without affecting the
instrumentation of the jobs themselves. It defaults to `true` and can also be
set through the `APPSIGNAL_ENABLE_JOB_ENQUEUE_INSTRUMENTATION` environment
variable.
6 changes: 0 additions & 6 deletions .changesets/instrument-que-enqueues.md

This file was deleted.

8 changes: 0 additions & 8 deletions .changesets/instrument-resque-enqueues.md

This file was deleted.

8 changes: 0 additions & 8 deletions .changesets/instrument-sidekiq-enqueues.md

This file was deleted.

9 changes: 0 additions & 9 deletions .changesets/title-sidekiq-delayed-enqueues-by-target.md

This file was deleted.

37 changes: 37 additions & 0 deletions lib/appsignal/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def dsl_config_file?
:enable_at_exit_hook => "on_error",
:enable_at_exit_reporter => true,
:enable_host_metrics => true,
:enable_job_enqueue_instrumentation => true,
:enable_minutely_probes => true,
:enable_statsd => true,
:enable_nginx_metrics => false,
Expand All @@ -113,13 +114,21 @@ def dsl_config_file?
:ignore_errors => [],
:ignore_logs => [],
:ignore_namespaces => [],
:instrument_active_job => true,
:instrument_code_ownership => true,
:instrument_delayed_job => true,
:instrument_excon => true,
:instrument_faraday => true,
:instrument_http_rb => true,
:instrument_mongo => true,
:instrument_net_http => true,
:instrument_ownership => true,
:instrument_que => true,
:instrument_redis => true,
:instrument_resque => true,
:instrument_sequel => true,
:instrument_shoryuken => true,
:instrument_sidekiq => true,
:log => "file",
:logging_endpoint => "https://appsignal-endpoint.net",
:ownership_set_namespace => false,
Expand Down Expand Up @@ -181,6 +190,8 @@ def dsl_config_file?
:enable_allocation_tracking => "APPSIGNAL_ENABLE_ALLOCATION_TRACKING",
:enable_at_exit_reporter => "APPSIGNAL_ENABLE_AT_EXIT_REPORTER",
:enable_host_metrics => "APPSIGNAL_ENABLE_HOST_METRICS",
:enable_job_enqueue_instrumentation =>
"APPSIGNAL_ENABLE_JOB_ENQUEUE_INSTRUMENTATION",
:enable_minutely_probes => "APPSIGNAL_ENABLE_MINUTELY_PROBES",
:enable_statsd => "APPSIGNAL_ENABLE_STATSD",
:enable_nginx_metrics => "APPSIGNAL_ENABLE_NGINX_METRICS",
Expand All @@ -192,13 +203,21 @@ def dsl_config_file?
:enable_rake_performance_instrumentation =>
"APPSIGNAL_ENABLE_RAKE_PERFORMANCE_INSTRUMENTATION",
:files_world_accessible => "APPSIGNAL_FILES_WORLD_ACCESSIBLE",
:instrument_active_job => "APPSIGNAL_INSTRUMENT_ACTIVE_JOB",
:instrument_code_ownership => "APPSIGNAL_INSTRUMENT_CODE_OWNERSHIP",
:instrument_delayed_job => "APPSIGNAL_INSTRUMENT_DELAYED_JOB",
:instrument_excon => "APPSIGNAL_INSTRUMENT_EXCON",
:instrument_faraday => "APPSIGNAL_INSTRUMENT_FARADAY",
:instrument_http_rb => "APPSIGNAL_INSTRUMENT_HTTP_RB",
:instrument_mongo => "APPSIGNAL_INSTRUMENT_MONGO",
:instrument_net_http => "APPSIGNAL_INSTRUMENT_NET_HTTP",
:instrument_ownership => "APPSIGNAL_INSTRUMENT_OWNERSHIP",
:instrument_que => "APPSIGNAL_INSTRUMENT_QUE",
:instrument_redis => "APPSIGNAL_INSTRUMENT_REDIS",
:instrument_resque => "APPSIGNAL_INSTRUMENT_RESQUE",
:instrument_sequel => "APPSIGNAL_INSTRUMENT_SEQUEL",
:instrument_shoryuken => "APPSIGNAL_INSTRUMENT_SHORYUKEN",
:instrument_sidekiq => "APPSIGNAL_INSTRUMENT_SIDEKIQ",
:ownership_set_namespace => "APPSIGNAL_OWNERSHIP_SET_NAMESPACE",
:running_in_container => "APPSIGNAL_RUNNING_IN_CONTAINER",
:send_environment_metadata => "APPSIGNAL_SEND_ENVIRONMENT_METADATA",
Expand Down Expand Up @@ -828,6 +847,8 @@ def activate_if_environment(*envs)
# @return [Boolean] Configure whether the at_exit reporter is enabled
# @!attribute [rw] enable_host_metrics
# @return [Boolean] Configure whether host metrics collection is enabled
# @!attribute [rw] enable_job_enqueue_instrumentation
# @return [Boolean] Configure whether to record an event when a background job is enqueued
# @!attribute [rw] enable_minutely_probes
# @return [Boolean] Configure whether minutely probes are enabled
# @!attribute [rw] enable_statsd
Expand All @@ -846,18 +867,34 @@ def activate_if_environment(*envs)
# @return [Boolean] Configure whether Rake performance instrumentation is enabled
# @!attribute [rw] files_world_accessible
# @return [Boolean] Configure whether files created by AppSignal should be world accessible
# @!attribute [rw] instrument_active_job
# @return [Boolean] Configure whether to instrument Active Job
# @!attribute [rw] instrument_delayed_job
# @return [Boolean] Configure whether to instrument Delayed Job
# @!attribute [rw] instrument_excon
# @return [Boolean] Configure whether to instrument requests made with the Excon gem
# @!attribute [rw] instrument_faraday
# @return [Boolean] Configure whether to instrument requests made with the Faraday gem
# @!attribute [rw] instrument_http_rb
# @return [Boolean] Configure whether to instrument requests made with the http.rb gem
# @!attribute [rw] instrument_mongo
# @return [Boolean] Configure whether to instrument MongoDB queries
# @!attribute [rw] instrument_net_http
# @return [Boolean] Configure whether to instrument requests made with Net::HTTP
# @!attribute [rw] instrument_ownership
# @return [Boolean] Configure whether to instrument the Ownership gem
# @!attribute [rw] instrument_que
# @return [Boolean] Configure whether to instrument Que
# @!attribute [rw] instrument_redis
# @return [Boolean] Configure whether to instrument Redis queries
# @!attribute [rw] instrument_resque
# @return [Boolean] Configure whether to instrument Resque
# @!attribute [rw] instrument_sequel
# @return [Boolean] Configure whether to instrument Sequel queries
# @!attribute [rw] instrument_shoryuken
# @return [Boolean] Configure whether to instrument Shoryuken
# @!attribute [rw] instrument_sidekiq
# @return [Boolean] Configure whether to instrument Sidekiq
# @!attribute [rw] ownership_set_namespace
# @return [Boolean] Configure whether the Ownership gem instrumentation should set namespace
# @!attribute [rw] running_in_container
Expand Down
12 changes: 11 additions & 1 deletion lib/appsignal/hooks/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def self.dependencies_present?
end

def dependencies_present?
self.class.dependencies_present?
self.class.dependencies_present? && Appsignal.config &&
Appsignal.config[:instrument_active_job]
end

def install
Expand Down Expand Up @@ -56,6 +57,15 @@ def install
# @!visibility private
module ActiveJobEnqueueInstrumentation
def enqueue(*, **)
# Skip recording the event when enqueue events are suppressed. That is
# the case when enqueue instrumentation is disabled, and it keeps this
# integration consistent with the standalone adapters (Sidekiq, ...),
# which already gate their own enqueue event on this check.
if Appsignal::Transaction.current? &&
Appsignal::Transaction.current.job_enqueue_events_suppressed?
return super
end

Appsignal.instrument("enqueue.active_job", "enqueue #{self.class.name} job") do
# Active Job enqueues through an adapter (Sidekiq, Resque, ...) that
# has its own enqueue instrumentation. Suppress it so the enqueue is
Expand Down
3 changes: 2 additions & 1 deletion lib/appsignal/hooks/delayed_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class DelayedJobHook < Appsignal::Hooks::Hook
register :delayed_job

def dependencies_present?
defined?(::Delayed::Plugin)
defined?(::Delayed::Plugin) && Appsignal.config &&
Appsignal.config[:instrument_delayed_job]
end

def install
Expand Down
2 changes: 1 addition & 1 deletion lib/appsignal/hooks/excon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ExconHook < Appsignal::Hooks::Hook
register :excon

def dependencies_present?
Appsignal.config && defined?(::Excon)
Appsignal.config && defined?(::Excon) && Appsignal.config[:instrument_excon]
end

def install
Expand Down
3 changes: 2 additions & 1 deletion lib/appsignal/hooks/mongo_ruby_driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class MongoRubyDriverHook < Appsignal::Hooks::Hook
register :mongo_ruby_driver

def dependencies_present?
defined?(::Mongo::Monitoring::Global)
defined?(::Mongo::Monitoring::Global) && Appsignal.config &&
Appsignal.config[:instrument_mongo]
end

def install
Expand Down
2 changes: 1 addition & 1 deletion lib/appsignal/hooks/que.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class QueHook < Appsignal::Hooks::Hook
register :que

def dependencies_present?
defined?(::Que::Job)
defined?(::Que::Job) && Appsignal.config && Appsignal.config[:instrument_que]
end

def install
Expand Down
2 changes: 1 addition & 1 deletion lib/appsignal/hooks/resque.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ResqueHook < Appsignal::Hooks::Hook
register :resque

def dependencies_present?
defined?(::Resque)
defined?(::Resque) && Appsignal.config && Appsignal.config[:instrument_resque]
end

def install
Expand Down
2 changes: 1 addition & 1 deletion lib/appsignal/hooks/shoryuken.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class ShoryukenHook < Appsignal::Hooks::Hook
register :shoryuken

def dependencies_present?
defined?(::Shoryuken)
defined?(::Shoryuken) && Appsignal.config && Appsignal.config[:instrument_shoryuken]
end

def install
Expand Down
3 changes: 2 additions & 1 deletion lib/appsignal/hooks/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def self.dependencies_present?
end

def dependencies_present?
self.class.dependencies_present?
self.class.dependencies_present? && Appsignal.config &&
Appsignal.config[:instrument_sidekiq]
end

def install
Expand Down
5 changes: 5 additions & 0 deletions lib/appsignal/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,11 @@ def suppress_job_enqueue_events

# @!visibility private
def job_enqueue_events_suppressed?
# When enqueue instrumentation is disabled, every enqueue integration
# treats its event as suppressed. That is how the config option turns the
# enqueue events off across all integrations at once.
return true if Appsignal.config && !Appsignal.config[:enable_job_enqueue_instrumentation]

store("job_enqueue")[:suppressed] == true
end

Expand Down
36 changes: 36 additions & 0 deletions sig/appsignal.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,10 @@ module Appsignal
sig { returns(T::Boolean) }
attr_accessor :enable_host_metrics

# _@return_ — Configure whether to record an event when a background job is enqueued
sig { returns(T::Boolean) }
attr_accessor :enable_job_enqueue_instrumentation

# _@return_ — Configure whether minutely probes are enabled
sig { returns(T::Boolean) }
attr_accessor :enable_minutely_probes
Expand Down Expand Up @@ -1218,6 +1222,18 @@ module Appsignal
sig { returns(T::Boolean) }
attr_accessor :files_world_accessible

# _@return_ — Configure whether to instrument Active Job
sig { returns(T::Boolean) }
attr_accessor :instrument_active_job

# _@return_ — Configure whether to instrument Delayed Job
sig { returns(T::Boolean) }
attr_accessor :instrument_delayed_job

# _@return_ — Configure whether to instrument requests made with the Excon gem
sig { returns(T::Boolean) }
attr_accessor :instrument_excon

# _@return_ — Configure whether to instrument requests made with the Faraday gem
sig { returns(T::Boolean) }
attr_accessor :instrument_faraday
Expand All @@ -1226,6 +1242,10 @@ module Appsignal
sig { returns(T::Boolean) }
attr_accessor :instrument_http_rb

# _@return_ — Configure whether to instrument MongoDB queries
sig { returns(T::Boolean) }
attr_accessor :instrument_mongo

# _@return_ — Configure whether to instrument requests made with Net::HTTP
sig { returns(T::Boolean) }
attr_accessor :instrument_net_http
Expand All @@ -1234,14 +1254,30 @@ module Appsignal
sig { returns(T::Boolean) }
attr_accessor :instrument_ownership

# _@return_ — Configure whether to instrument Que
sig { returns(T::Boolean) }
attr_accessor :instrument_que

# _@return_ — Configure whether to instrument Redis queries
sig { returns(T::Boolean) }
attr_accessor :instrument_redis

# _@return_ — Configure whether to instrument Resque
sig { returns(T::Boolean) }
attr_accessor :instrument_resque

# _@return_ — Configure whether to instrument Sequel queries
sig { returns(T::Boolean) }
attr_accessor :instrument_sequel

# _@return_ — Configure whether to instrument Shoryuken
sig { returns(T::Boolean) }
attr_accessor :instrument_shoryuken

# _@return_ — Configure whether to instrument Sidekiq
sig { returns(T::Boolean) }
attr_accessor :instrument_sidekiq

# _@return_ — Configure whether the Ownership gem instrumentation should set namespace
sig { returns(T::Boolean) }
attr_accessor :ownership_set_namespace
Expand Down
Loading
Loading