aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorDaniel Schierbeck <daniel.schierbeck@gmail.com>2018-10-24 16:00:31 +0200
committerJeremy Daer <jeremydaer@gmail.com>2019-03-19 08:35:09 -0700
commit04ae0b0b5e594e0bb99c5cd608921745977bcdcd (patch)
treec01abaa20879bdcc3ae50ddb90afe285f824447c /actionpack/lib/action_dispatch
parent299573adc60fe0f7aa68f9c66df5ffe2efb0df40 (diff)
downloadrails-04ae0b0b5e594e0bb99c5cd608921745977bcdcd.tar.gz
rails-04ae0b0b5e594e0bb99c5cd608921745977bcdcd.tar.bz2
rails-04ae0b0b5e594e0bb99c5cd608921745977bcdcd.zip
Instrument middleware processing
Adds ActiveSupport::Notifications instrumentation of the processing of each middleware in the stack.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/middleware/stack.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb
index 7a2fcd6db7..f0c869fba0 100644
--- a/actionpack/lib/action_dispatch/middleware/stack.rb
+++ b/actionpack/lib/action_dispatch/middleware/stack.rb
@@ -34,7 +34,28 @@ module ActionDispatch
end
def build(app)
- klass.new(app, *args, &block)
+ InstrumentationProxy.new(klass.new(app, *args, &block), inspect)
+ end
+ end
+
+ # This class is used to instrument the execution of a single middleware.
+ # It proxies the `call` method transparently and instruments the method
+ # call.
+ class InstrumentationProxy
+ EVENT_NAME = "process_middleware.action_dispatch"
+
+ def initialize(middleware, class_name)
+ @middleware = middleware
+
+ @payload = {
+ middleware: class_name,
+ }
+ end
+
+ def call(env)
+ ActiveSupport::Notifications.instrument(EVENT_NAME, @payload) do
+ @middleware.call(env)
+ end
end
end