Module: ScoutApm::Instruments::ActionControllerRails2Instruments

Defined in:
lib/scout_apm/instruments/action_controller_rails_2.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(instrumented_class) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# 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

Instance Method Details

#perform_action_with_scout_instruments(*args, &block) ⇒ Object

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.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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