Created
February 15, 2013 15:04
-
-
Save daveyeu/4960893 to your computer and use it in GitHub Desktop.
Displays accurate request queue times for New Relic on Heroku Cedar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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