Skip to content

Instantly share code, notes, and snippets.

@indirect
Created November 17, 2011 17:44
Show Gist options
  • Save indirect/1373864 to your computer and use it in GitHub Desktop.
Save indirect/1373864 to your computer and use it in GitHub Desktop.
Rack middleware so NewRelic shows time as ruby
# This adds a request header so NewRelic knows when the middleware stack
# started processing. Hopefully this means we'll get better metrics, split
# between actual request queueing and time spent in the middlewares.
module Plex
class MiddlewareStart
def initialize(app)
@app = app
end
def call(env)
env["HTTP_X_MIDDLEWARE_START"] = "t=#{(Time.now.to_f * 1000000).to_i}"
@app.call(env)
end
end
end
Rails.application.middleware.insert(0, Plex::MiddlewareStart)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment