Skip to content

Commit

Permalink
Adding auto_instruments_ignore config option
Browse files Browse the repository at this point in the history
This adds a `auto_instruments_ignore` config option so files can be excluded from autoinstruments. By defaut this is an empty array. Example usage: `auto_instruments_ignore: ['application_controller']`.
  • Loading branch information
itsderek23 committed Sep 23, 2019
1 parent 84575a5 commit 551f561
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/scout_apm/auto_instrument/instruction_sequence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ module ScoutApm
module AutoInstrument
module InstructionSequence
def load_iseq(path)
if Rails.controller_path?(path)
if Rails.controller_path?(path) & !Rails.ignore?(path)
begin
new_code = Rails.rewrite(path)
return self.compile(new_code, File.basename(path), path)
rescue
warn "Failed to apply auto-instrumentation to #{path}: #{$!}"
end
elsif Rails.ignore?(path)
warn "AutoInstruments are ignored for path=#{path}."
end

return self.compile_file(path)
end
end
Expand Down
13 changes: 13 additions & 0 deletions lib/scout_apm/auto_instrument/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ def self.controller_path? path
CONTROLLER_FILE.match(path) && !GEM_FILE.match(path)
end

# Autoinstruments increases overhead when applied to many code expressions that perform little work.
# You can exclude files from autoinstruments via the `auto_instruments_ignore` option.
def self.ignore?(path)
res = false
ScoutApm::Agent.instance.context.config.value('auto_instruments_ignore').each do |ignored_file_name|
if path.include?(ignored_file_name)
res = true
break
end
end
res
end

def self.rewrite(path, code = nil)
code ||= File.read(path)

Expand Down
10 changes: 7 additions & 3 deletions lib/scout_apm/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# start_resque_server_instrument - Used in special situations with certain Resque installs
# timeline_traces - true/false to enable sending of of the timeline trace format.
# auto_instruments - true/false whether to install autoinstruments. Only installed if on a supported Ruby version.
# auto_instruments_ignore - An array of file names to exclude from autoinstruments (Ex: ['application_controller']).
#
# Any of these config settings can be set with an environment variable prefixed
# by SCOUT_ and uppercasing the key: SCOUT_LOG_LEVEL for instance.
Expand Down Expand Up @@ -77,7 +78,8 @@ class Config
'uri_reporting',
'instrument_http_url_length',
'timeline_traces',
'auto_instruments'
'auto_instruments',
'auto_instruments_ignore'
]

################################################################################
Expand Down Expand Up @@ -171,7 +173,8 @@ def coerce(val)
'instrument_http_url_length' => IntegerCoercion.new,
'start_resque_server_instrument' => BooleanCoercion.new,
'timeline_traces' => BooleanCoercion.new,
'auto_instruments' => BooleanCoercion.new
'auto_instruments' => BooleanCoercion.new,
'auto_instruments_ignore' => JsonCoercion.new,
}


Expand Down Expand Up @@ -280,7 +283,8 @@ class ConfigDefaults
'start_resque_server_instrument' => true, # still only starts if Resque is detected
'collect_remote_ip' => true,
'timeline_traces' => true,
'auto_instruments' => false
'auto_instruments' => false,
'auto_instruments_ignore' => []
}.freeze

def value(key)
Expand Down

0 comments on commit 551f561

Please sign in to comment.