-
-
Save a-warner/f5db30857ed3423cea79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# combination of https://gist.github.com/daveyeu/4960893 | |
# and https://gist.github.com/jasonrclark/d82a1ea7695daac0b9ee | |
class QueueTimeLogger | |
attr_reader :app | |
def initialize(app, options = {}) | |
@app = app | |
end | |
def call(env) | |
now = Time.now.to_f | |
# Delete Heroku's queue time header because it's incorrect and useless | |
env.delete("HTTP_X_HEROKU_QUEUE_WAIT_TIME") | |
microseconds = (now * 1_000_000).to_i | |
env["HTTP_X_MIDDLEWARE_START"] = "t=#{microseconds}" | |
if env["HTTP_X_REQUEST_START"] | |
# HTTP_X_REQUEST_START is expected by New Relic to have a t= leading | |
# but currently doesn't, so it can just get to_i applied. | |
request_start_microseconds = env["HTTP_X_REQUEST_START"].to_i * 1_000 | |
queue_time_microseconds = microseconds - request_start_microseconds | |
env["HTTP_X_QUEUE_TIME"] = "t=#{queue_time_microseconds}" | |
end | |
app.call(env) | |
end | |
end |
Thanks @a-warner but it was a totally unrelated issue (I had been trying out ruby 2.0.0 preview and switching back to 1.9.3 had broken the session cookie).
The gem looks great (I had started writing one myself but I'll give up on that now), thanks
do i need to modify my new relic or heroku configuration for the gem to work out of the box? i've just deployed this to a staging app I have running on the cedar stack with new relic standard, and am throwing a ton of requests at it with ab, but am seeing 0 queueing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey all - check out https://github.com/RapGenius/heroku-true-relic, which is a gem version of this gist. We'll try to keep that up to date as we get more information about how best to track dyno-level queuing.
@dblock Thanks for the tip on not reporting negative queue time numbers; I incorporated that into the gem.