mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #36221 from jhawthorn/middleware_instrumentation
Only build middleware proxy when instrumentating
This commit is contained in:
commit
dd868aa0c8
3 changed files with 17 additions and 6 deletions
|
@ -34,7 +34,11 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(app)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -119,7 +123,14 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def build(app = nil, &block)
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -99,7 +99,7 @@ module ShowExceptions
|
||||||
class ShowFailsafeExceptionsTest < ActionDispatch::IntegrationTest
|
class ShowFailsafeExceptionsTest < ActionDispatch::IntegrationTest
|
||||||
def test_render_failsafe_exception
|
def test_render_failsafe_exception
|
||||||
@app = ShowExceptionsOverriddenController.action(:boom)
|
@app = ShowExceptionsOverriddenController.action(:boom)
|
||||||
middleware = @app.instance_variable_get(:@middleware)
|
middleware = @app
|
||||||
@exceptions_app = middleware.instance_variable_get(:@exceptions_app)
|
@exceptions_app = middleware.instance_variable_get(:@exceptions_app)
|
||||||
middleware.instance_variable_set(:@exceptions_app, nil)
|
middleware.instance_variable_set(:@exceptions_app, nil)
|
||||||
$stderr = StringIO.new
|
$stderr = StringIO.new
|
||||||
|
|
|
@ -121,9 +121,6 @@ class MiddlewareStackTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "instruments the execution of middlewares" do
|
test "instruments the execution of middlewares" do
|
||||||
app = @stack.build(proc { |env| [200, {}, []] })
|
|
||||||
env = {}
|
|
||||||
|
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
subscriber = proc do |*args|
|
subscriber = proc do |*args|
|
||||||
|
@ -131,6 +128,9 @@ class MiddlewareStackTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
ActiveSupport::Notifications.subscribed(subscriber, "process_middleware.action_dispatch") do
|
ActiveSupport::Notifications.subscribed(subscriber, "process_middleware.action_dispatch") do
|
||||||
|
app = @stack.build(proc { |env| [200, {}, []] })
|
||||||
|
|
||||||
|
env = {}
|
||||||
app.call(env)
|
app.call(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue