Skip to content

Instantly share code, notes, and snippets.

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 lorennorman/aa8c743635e6d838552fa3168e9b5881 to your computer and use it in GitHub Desktop.
Save lorennorman/aa8c743635e6d838552fa3168e9b5881 to your computer and use it in GitHub Desktop.
drop-in initializer for tracing the Rails middleware stack, useful when you can't tell what is handling a request
# Draws the Middleware stack as the request propogates in and out.
module MiddlewareTracer
def call(env)
# request = ActionDispatch::Request.new(env)
puts "-> #{self.class.name}:"
status, headers, response = super(env)
puts "<- #{self.class.name}, Status: #{status}"
[status, headers, response]
end
end
# Instrument the middleware stack after initialization so that we
# know the stack won't be changed afterwards.
Rails.configuration.after_initialize do
Rails.application.middleware.each do |middleware|
klass = middleware.klass
# There are a few odd middlewares that aren't classes.
klass.prepend(MiddlewareTracer) if klass.respond_to?(:prepend)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment