diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2019-05-08 17:00:35 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-08 17:00:35 -0400 |
commit | dd868aa0c82ab45d1ca21febf179bb5cd1c21766 (patch) | |
tree | 866b93d0aa56cf3fcca33ecf92b215f1ddc1393b /actionpack | |
parent | 52125dc0f8669d8dd497427c7b177d5d04106e0c (diff) | |
parent | 6f549ce53f3398403d4c2a47f9ecba910be256dd (diff) | |
download | rails-dd868aa0c82ab45d1ca21febf179bb5cd1c21766.tar.gz rails-dd868aa0c82ab45d1ca21febf179bb5cd1c21766.tar.bz2 rails-dd868aa0c82ab45d1ca21febf179bb5cd1c21766.zip |
Merge pull request #36221 from jhawthorn/middleware_instrumentation
Only build middleware proxy when instrumentating
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/stack.rb | 15 | ||||
-rw-r--r-- | actionpack/test/controller/show_exceptions_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/middleware_stack_test.rb | 6 |
3 files changed, 17 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index f0c869fba0..57e4adb457 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -34,7 +34,11 @@ module ActionDispatch 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 @@ -119,7 +123,14 @@ module ActionDispatch 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 diff --git a/actionpack/test/controller/show_exceptions_test.rb b/actionpack/test/controller/show_exceptions_test.rb index 8724f9bcdb..1d68a359dc 100644 --- a/actionpack/test/controller/show_exceptions_test.rb +++ b/actionpack/test/controller/show_exceptions_test.rb @@ -99,7 +99,7 @@ module ShowExceptions class ShowFailsafeExceptionsTest < ActionDispatch::IntegrationTest def test_render_failsafe_exception @app = ShowExceptionsOverriddenController.action(:boom) - middleware = @app.instance_variable_get(:@middleware) + middleware = @app @exceptions_app = middleware.instance_variable_get(:@exceptions_app) middleware.instance_variable_set(:@exceptions_app, nil) $stderr = StringIO.new diff --git a/actionpack/test/dispatch/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb index 90f2eccd19..c534e60c74 100644 --- a/actionpack/test/dispatch/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb @@ -121,9 +121,6 @@ class MiddlewareStackTest < ActiveSupport::TestCase end test "instruments the execution of middlewares" do - app = @stack.build(proc { |env| [200, {}, []] }) - env = {} - events = [] subscriber = proc do |*args| @@ -131,6 +128,9 @@ class MiddlewareStackTest < ActiveSupport::TestCase end ActiveSupport::Notifications.subscribed(subscriber, "process_middleware.action_dispatch") do + app = @stack.build(proc { |env| [200, {}, []] }) + + env = {} app.call(env) end |