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



35
36
37
38
39
40
41
42
43
44
# File 'lib/scout_apm/instruments/action_controller_rails_2.rb', line 35

def self.included(instrumented_class)
  ScoutApm::Agent.instance.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.



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/scout_apm/instruments/action_controller_rails_2.rb', line 49

def perform_action_with_scout_instruments(*args, &block)
  req = ScoutApm::RequestManager.lookup
  path = ScoutApm::Agent.instance.config.value("uri_reporting") == 'path' ? request.path : request.fullpath
  req.annotate_request(:uri => path)
  req.context.add_user(:ip => request.remote_ip)
  req.set_headers(request.headers)
  req.start_layer( ScoutApm::Layer.new("Controller", "#{controller_path}/#{action_name}") )
  req.web!

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