Skip to content

Instantly share code, notes, and snippets.

@ryandotsmith
Last active December 15, 2015 00:19
Show Gist options
  • Save ryandotsmith/5172179 to your computer and use it in GitHub Desktop.
Save ryandotsmith/5172179 to your computer and use it in GitHub Desktop.
Time rack requests and print heroku request id
class RackTimer
def initialize(app)
@app = app
end
def call(env)
start_request = Time.now
status, headers, body = @app.call(env)
elapsed = (Time.now - start_request) * 1000
$stdout.puts("request-id=#{env['HTTP_HEROKU_REQUEST_ID']} measure.rack-request=#{elapsed.round}ms")
[status, headers, body]
end
end
@a-warner
Copy link

a-warner commented Apr 3, 2013

maybe it's better to tap the result vs keeping the variables around?

start_request = Time.now
@app.call(env).tap do
  elapsed = (Time.now - start_request) * 1000
  $stdout.puts("request-id=#{env['HTTP_HEROKU_REQUEST_ID']} measure.rack-request=#{elapsed}ms")
end

@dfuentes77
Copy link

Would you recommended an expanded version like: https://gist.github.com/chinshr/5314155

In either case, where exactly would I put it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment