Module: RailsServerTimings::ControllerRuntime

Defined in:
lib/rails_server_timings/controller_runtime.rb

Instance Method Summary collapse

Instance Method Details

#process_action(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rails_server_timings/controller_runtime.rb', line 3

def process_action(*args)
  callback = lambda do |*_|
    event = ActiveSupport::Notifications::Event.new(*_)
    payload = event.payload
    timings = []

    payload.each do |key, value|
      if key.to_s =~ /\w+_runtime$/
        timings << ("#{key.to_s.chomp('_runtime')}; dur=%.3f" % value.to_f)
      end
    end

    timings << ('total; dur=%.3f' % event.duration.to_f)

    response.headers['Server-Timing'] = timings.join(', ')
  end


  ActiveSupport::Notifications.subscribed(callback, 'process_action.action_controller') do
    super
  end
end