Skip to content

Instantly share code, notes, and snippets.

@daveyeu
Created February 15, 2013 15:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveyeu/4960893 to your computer and use it in GitHub Desktop.
Save daveyeu/4960893 to your computer and use it in GitHub Desktop.
Displays accurate request queue times for New Relic on Heroku Cedar
# Accurate queue times for Heroku Cedar + Rails (or Rack)
#
# For Rails:
#
# Rails::Application.middleware.insert(0, QueueTimeLogger)
#
class QueueTimeLogger
attr_reader :app
def initialize(app, options = {})
@app = app
end
def call(env)
now_us = (Time.now.to_f * 1000000).to_i
request_start_us = env["HTTP_X_REQUEST_START"].to_i * 1000
queue_time_us = now_us - request_start_us
env["HTTP_X_QUEUE_TIME"] = "t=#{queue_time_us}"
# This overrides HTTP_X_QUEUE_TIME and doesn't provide anything meaningful.
env.delete("HTTP_X_HEROKU_QUEUE_WAIT_TIME")
app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment