module ScoutApm::Instruments::ActionControllerRails2Instruments

Public Class Methods

included(instrumented_class) click to toggle source
# File lib/scout_apm/instruments/action_controller_rails_2.rb, line 39
def self.included(instrumented_class)
  # XXX: Don't lookup context by global
  ScoutApm::Agent.instance.context.logger.info "Instrumenting #{instrumented_class.inspect}"
  instrumented_class.class_eval do
    unless instrumented_class.method_defined?(:perform_action_without_scout_instruments)
      alias_method :perform_action_without_scout_instruments, :perform_action
      alias_method :perform_action, :perform_action_with_scout_instruments
      private :perform_action
    end
  end
end

Public Instance Methods

perform_action_with_scout_instruments(*args, &block) click to toggle source

In addition to instrumenting actions, this also sets the scope to the controller action name. The scope is later applied to metrics recorded during this transaction. This lets us associate ActiveRecord calls with specific controller actions.

# File lib/scout_apm/instruments/action_controller_rails_2.rb, line 54
def perform_action_with_scout_instruments(*args, &block)
  req = ScoutApm::RequestManager.lookup
  req.annotate_request(:uri => request.path) # for security by-default, we don't use request.fullpath which could reveal filtered params.
  if ScoutApm::Agent.instance.context.config.value('collect_remote_ip')
    req.context.add_user(:ip => request.remote_ip)
  end
  req.set_headers(request.headers)
  req.start_layer( ScoutApm::Layer.new("Controller", "#{controller_path}/#{action_name}") )

  begin
    perform_action_without_scout_instruments(*args, &block)
  rescue
    req.error!
    raise
  ensure
    req.stop_layer
  end
end