module ScoutApm::AutoInstrument::Rails
Constants
- CONTROLLER_FILE
-
A general pattern to match
Rails
controller files: - GEM_FILE
-
Some gems (Devise) provide controllers that match
CONTROLLER_FILE
pattern. Try a simple match to see if it’s a Gemfile
Public Class Methods
Source
# File lib/scout_apm/auto_instrument/rails.rb, line 16 def self.controller_path? path CONTROLLER_FILE.match(path) && !GEM_FILE.match(path) end
Whether the given path is likely to be a Rails
controller and not provided by a Gem.
Source
# File lib/scout_apm/auto_instrument/rails.rb, line 22 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
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.
Source
# File lib/scout_apm/auto_instrument/rails.rb, line 33 def self.rewrite(path, code = nil) code ||= File.read(path) ast = ::Parser::CurrentRuby.parse(code) # pp ast buffer = ::Parser::Source::Buffer.new(path) buffer.source = code rewriter = Rewriter.new # Rewrite the AST, returns a String with the new form. rewriter.rewrite(buffer, ast) end