Module: ScoutApm::AutoInstrument::Rails

Defined in:
lib/scout_apm/auto_instrument/rails.rb

Constant Summary collapse

CONTROLLER_FILE =

A general pattern to match Rails controller files:

/\/app\/controllers\/*\/.*_controller.rb$/.freeze
GEM_FILE =

Some gems (Devise) provide controllers that match CONTROLLER_FILE pattern. Try a simple match to see if it’s a Gemfile

/\/gems?\//.freeze

Class Method Summary collapse

Class Method Details

.controller_path?(path) ⇒ Boolean

Whether the given path is likely to be a Rails controller and not provided by a Gem.

Returns:

  • (Boolean)


20
21
22
# File 'lib/scout_apm/auto_instrument/rails.rb', line 20

def self.controller_path? path
  CONTROLLER_FILE.match(path) && !GEM_FILE.match(path)
end

.ignore?(path) ⇒ Boolean

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.

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
# File 'lib/scout_apm/auto_instrument/rails.rb', line 26

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

.rewrite(path, code = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/scout_apm/auto_instrument/rails.rb', line 37

def self.rewrite(path, code = nil)
  if defined?(Prism)
    PrismImplementation.rewrite(path, code)
  else
    ParserImplementation.rewrite(path, code)
  end
end