Skip to content

Commit

Permalink
Refactor Rails::Rack::Logger to avoid adding a new param to call_app
Browse files Browse the repository at this point in the history
ref: rails#50992 (comment)

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.
  • Loading branch information
ghiculescu authored and rafaelfranca committed Feb 15, 2024
1 parent 9b343c2 commit 363abea
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions railties/lib/rails/rack/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 363abea

Please sign in to comment.