From 363abead1776d8a44123be0f4991db05acc3bb74 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 13 Feb 2024 10:28:05 +1000 Subject: [PATCH] Refactor `Rails::Rack::Logger` to avoid adding a new param to `call_app` ref: https://github.com/rails/rails/pull/50992#issuecomment-1939865460 This refactors the implementation from that PR so that we don't need a new param on the `call_app` method. This means we don't break any gems or apps that have overridden it. --- railties/lib/rails/rack/logger.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb index 1b561c4f1a89c..892c8ddc0f2c3 100644 --- a/railties/lib/rails/rack/logger.rb +++ b/railties/lib/rails/rack/logger.rb @@ -20,16 +20,19 @@ def initialize(app, taggers = nil) def call(env) request = ActionDispatch::Request.new(env) - logger_tag_pop_count = if logger.respond_to?(:push_tags) + env["rails.rack_logger_tag_count"] = if logger.respond_to?(:push_tags) logger.push_tags(*compute_tags(request)).size else 0 end - call_app(request, env, logger_tag_pop_count) + + call_app(request, env) end private - def call_app(request, env, logger_tag_pop_count) # :doc: + def call_app(request, env) # :doc: + logger_tag_pop_count = env["rails.rack_logger_tag_count"] + instrumenter = ActiveSupport::Notifications.instrumenter handle = instrumenter.build_handle("request.action_dispatch", { request: request }) handle.start