Created
April 20, 2020 17:03
-
-
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
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
# 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