Module: ProfileIt::Instruments::ActionControllerInstruments
- Defined in:
- lib/profile_it/instruments/rails/action_controller_instruments.rb,
lib/profile_it/instruments/rails3_or_4/action_controller_instruments.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#perform_action_with_profile_it_instruments(*args, &block) ⇒ Object
In addition to instrumenting actions, this also sets the scope to the controller action name.
-
#process_action(*args) ⇒ Object
Instruments the action and tracks errors.
Class Method Details
.included(instrumented_class) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/profile_it/instruments/rails/action_controller_instruments.rb', line 3 def self.included(instrumented_class) ProfileIt::Agent.instance.logger.debug "Instrumenting #{instrumented_class.inspect}" instrumented_class.class_eval do unless instrumented_class.method_defined?(:perform_action_without_profile_it_instruments) alias_method :perform_action_without_profile_it_instruments, :perform_action alias_method :perform_action, :perform_action_with_profile_it_instruments private :perform_action end end end |
Instance Method Details
#perform_action_with_profile_it_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 profile. This lets us associate ActiveRecord calls with specific controller actions.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/profile_it/instruments/rails/action_controller_instruments.rb', line 17 def perform_action_with_profile_it_instruments(*args, &block) key_from_headers = request.headers['x-profileit-key'] if !key_from_headers.blank? && key_from_headers == ProfileIt::Agent.instance.config.settings['key'] profile_it_controller_action = "Controller/#{controller_path}/#{action_name}" Thread::current[:profile_it_extension_fingerprint]=request.headers['x-profileit-extension-fingerprint'] Thread::current[:profile_it_extension_version]=request.headers['x-profileit-extension-version'] Thread::current[:profile_it_user_id]=request.headers['x-profileit-user-id'] request_id = SecureRandom.hex(16) # since rails 2 doesn't set an x-request-id header, generate our own response.headers['x-profileit-request-id'] = request_id self.class.profile_request(profile_it_controller_action, :uri => request.request_uri, :request_id=>request_id) do perform_action_without_profile_it_instruments(*args, &block) end else perform_action_without_profile_it_instruments(*args, &block) end end |
#process_action(*args) ⇒ Object
Instruments the action and tracks errors.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/profile_it/instruments/rails3_or_4/action_controller_instruments.rb', line 5 def process_action(*args) key_from_headers = request.headers['x-profileit-key'] # ProfileIt::Agent.instance.logger.debug "in perform_action_with_profile_it_instruments request key = #{key_from_headers}. config key = #{ProfileIt::Agent.instance.config.settings['key']}. " if !key_from_headers.blank? && key_from_headers == ProfileIt::Agent.instance.config.settings['key'] profile_it_controller_action = "Controller/#{controller_path}/#{action_name}" self.class.profile_request(profile_it_controller_action, :uri => request.fullpath, :request_id => request.env["action_dispatch.request_id"]) do Thread::current[:profile_it_extension_fingerprint]=request.headers['x-profileit-extension-fingerprint'] Thread::current[:profile_it_extension_version]=request.headers['x-profileit-extension-version'] Thread::current[:profile_it_user_id]=request.headers['x-profileit-user-id'] begin super rescue Exception => e raise ensure Thread::current[:profile_it_scope_name] = nil end end else super end end |