Skip to content

Instantly share code, notes, and snippets.

@jasonrclark
Forked from daveyeu/gist:e2f9cc33c3e407dbc6fc
Last active December 12, 2015 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonrclark/d82a1ea7695daac0b9ee to your computer and use it in GitHub Desktop.
Save jasonrclark/d82a1ea7695daac0b9ee to your computer and use it in GitHub Desktop.
now = Time.now.to_f
milliseconds = (now * 1_000).to_i
microseconds = (now * 1_000_000).to_i
# Wait time doesn't seem to represent queue time like we want to capture
env.delete("HTTP_X_HEROKU_QUEUE_WAIT_TIME")
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_milliseconds = env["HTTP_X_REQUEST_START"].to_i
request_start_microseconds = request_start_milliseconds * 1_000
queue_time_milliseconds = milliseconds - request_start_milliseconds
queue_time_microseconds = microseconds - request_start_microseconds
env["HTTP_X_QUEUE_TIME"] = "t=#{queue_time_microseconds}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment