Repository navigation
Remove Rails' event reporter log subscribers on Rails 8.2+ - #412
Merged
Merged
Conversation
Rails 8.2 (rails/rails#55900) moved ActionController::LogSubscriber and ActionView::LogSubscriber onto ActiveSupport::EventReporter::LogSubscriber, subscribed to ActiveSupport.event_reporter rather than ActiveSupport::Notifications. remove_existing_log_subscriptions no longer found them, so Rails' "Processing by" / "Completed" lines were logged alongside lograge's line. Also unsubscribe these classes from ActiveSupport.event_reporter when they are event reporter log subscribers. The Notifications-based removal for earlier Rails versions is unchanged. Update the specs for both subscriber systems, and stop mutating ExceptionWrapper.rescue_responses in place, since Rails main freezes it. Fixes #407
…pecs Mark the two new event reporter helpers as private class methods so they don't become part of Lograge's public API, and drop the redundant ActiveSupport.respond_to?(:event_reporter) check. Restore ActionDispatch::ExceptionWrapper.rescue_responses after the 404 specs so the RecordNotFound mapping doesn't leak into other examples.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #407.
Problem
rails/rails#55900 changed
ActionController::LogSubscriberandActionView::LogSubscriberto inherit fromActiveSupport::EventReporter::LogSubscriber. They are now subscribed toActiveSupport.event_reporter, notActiveSupport::Notifications.Lograge.remove_existing_log_subscriptionsonly looks inActiveSupport::LogSubscriber.log_subscribers, so on Rails main it finds nothing to remove. Rails'Processing by …/Completed 200 OK …lines are logged next to lograge's line.lograge's own subscriber is not affected.
process_action.action_controlleris still sent throughActiveSupport::Notifications.Change
remove_existing_log_subscriptionsnow also callsActiveSupport.event_reporter.unsubscribeforActionController::LogSubscriberandActionView::LogSubscriber. It only does this when those classes inherit fromActiveSupport::EventReporter::LogSubscriber. Removal for Rails ≤ 8.1 is unchanged.RecordNotFound404 specs no longer changeActionDispatch::ExceptionWrapper.rescue_responsesin place, because Rails main now freezes it. That was a separate cause of the edge CI failures.Testing
Rubocop reports no offenses.
Notes
continue-on-error, which is why these failures went unnoticed. It might be worth making edge failures visible as a follow-up.ActionDispatch::LogSubscriberto the event reporter. lograge has never removed that one, so route-level redirects still produce Rails' own log lines, the same as on earlier versions.