lib/action_dispatch/middleware/stack.rb in actionpack-6.0.0.rc1 vs lib/action_dispatch/middleware/stack.rb in actionpack-6.0.0.rc2

- old
+ new

@@ -32,12 +32,16 @@ klass.class.to_s end end def build(app) - InstrumentationProxy.new(klass.new(app, *args, &block), inspect) + klass.new(app, *args, &block) end + + def build_instrumented(app) + InstrumentationProxy.new(build(app), 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. @@ -117,10 +121,17 @@ def use(klass, *args, &block) middlewares.push(build_middleware(klass, args, block)) end def build(app = nil, &block) - middlewares.freeze.reverse.inject(app || block) { |a, e| e.build(a) } + instrumenting = ActiveSupport::Notifications.notifier.listening?(InstrumentationProxy::EVENT_NAME) + middlewares.freeze.reverse.inject(app || block) do |a, e| + if instrumenting + e.build_instrumented(a) + else + e.build(a) + end + end end private def assert_index(index, where)