"active"," /> "active"," /> "active","/>

How to expose ActiveSupport instrumentation metrics as HTTP response headers in Rails?

38 Views Asked by At
(78.3ms) ItemsController -- Completed #active -- { :view_runtime => 10.46, :db_runtime => 6.76, :controller => "ItemsController", :action => "active", :format => "*/*", :method => "GET", :path => "/active", :status => 200, :status_message => "OK" }

I'm wondering if there is any simple method of exposing these ActiveSupport Instrumentation metrics(view_runtime, db_runtime) as HTTP response headers.

My use case is the following:

staging/beta environment that's a bit annoying to get into(VPN + ssh + cat/grep/tail) + it is used pretty heavily so it's not very easy to spot the messages I'm looking for. But if it was accessible in Web inspector for AJAX requests, then it is better visibility.

Just to be clear, I'm aware of New Relic but this would be an overkill for such a simple task.

1

There are 1 best solutions below

0
Nikita Fedyashev On

Ok, view_runtime might be harder to get in a controller but db_runtime seems to be pretty straightforward if there aren't any queries triggered from templates.

db_runtime = ActiveRecord::LogSubscriber.runtime
response.headers['db_runtime'] = ("ActiveRecord: %.1fms" % db_runtime.to_f) if db_runtime