1
0

instrumentation.rb 1.0 KB

123456789101112131415161718
  1. # frozen_string_literal: true
  2. instrumentation_hostname = ENV.fetch('INSTRUMENTATION_HOSTNAME') { 'localhost' }
  3. ActiveSupport::Notifications.subscribe(/process_action.action_controller/) do |*args|
  4. event = ActiveSupport::Notifications::Event.new(*args)
  5. controller = event.payload[:controller]
  6. action = event.payload[:action]
  7. format = event.payload[:format] || 'all'
  8. format = 'all' if format == '*/*'
  9. status = event.payload[:status]
  10. key = "#{controller}.#{action}.#{format}.#{instrumentation_hostname}"
  11. ActiveSupport::Notifications.instrument :performance, action: :measure, measurement: "#{key}.total_duration", value: event.duration
  12. ActiveSupport::Notifications.instrument :performance, action: :measure, measurement: "#{key}.db_time", value: event.payload[:db_runtime]
  13. ActiveSupport::Notifications.instrument :performance, action: :measure, measurement: "#{key}.view_time", value: event.payload[:view_runtime]
  14. ActiveSupport::Notifications.instrument :performance, measurement: "#{key}.status.#{status}"
  15. end