Skip to content

Add silenced? for Action View Start subscriber - #50751

Merged
byroot merged 1 commit into
rails:mainfrom
skipkayhil:hm-av-silenceable-start
Jan 16, 2024
Merged

byroot merged 1 commit into
rails:mainfrom
skipkayhil:hm-av-silenceable-start

Conversation

@skipkayhil

@skipkayhil skipkayhil commented Jan 14, 2024 •

Copy link
Copy Markdown
Member

Motivation / Background

Ref #45796

Previously, the render_template.action_view and render_layout.action_view events would always be handled as if they had subscribers even if the log level of its subscribers result in nothing being logged. For regular LogSubscribers, subscribe_log_level could be used to optimize these cases but the Start subscriber is not a subclass of LogSubscriber.

Detail

This commit implements a #silenced? method for the Start subscriber so that it can also benefit from the subscribe_log_level optimization.

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot Bot added the actionview label Jan 14, 2024
Previously, the `render_template.action_view` and
`render_layout.action_view` events would always be handled as if they
had subscribers even if the log level of its subscribers result in
nothing being logged. For regular `LogSubscriber`s,
`subscribe_log_level` could be used to optimize these cases but the
Start subscriber is not a subclass of `LogSubscriber`.

This commit implements a `#subscribed?` method for the Start subscriber
so that it can also benefit from the `subscribe_log_level` optimization.
@skipkayhil
skipkayhil force-pushed the hm-av-silenceable-start branch from ef19528 to d255ffd Compare January 15, 2024 20:47
@byroot
byroot merged commit 6a9795d into rails:main Jan 16, 2024
@skipkayhil
skipkayhil deleted the hm-av-silenceable-start branch January 16, 2024 22:36
nuclearspike added a commit to nuclearspike/rails that referenced this pull request Jul 27, 2026
The structured-events rewrite (rails#55690) replaced the old render Start
subscriber with a new class that dropped the silenced? method rails#50751 had
added to its predecessor. Because the notifications Fanout treats
subscribers without silenced? as permanently active,
render_template.action_view and render_layout.action_view now run the
full instrumentation machinery on every render in every environment,
only for the emission to no-op inside ActiveSupport.event_reporter.debug
when debug mode is off (the default outside development).

Restoring silenced? (using the same two-condition shape as
ActiveSupport::StructuredEventSubscriber#silenced? and the original
rails#50751 fix) lets the notification layer skip that work at the source,
exactly as the pre-structured-events subscriber did. Behavior in debug
mode is unchanged.

Co-Authored-By: Claude Fable 5 <[email protected]>
nuclearspike added a commit to nuclearspike/rails that referenced this pull request Jul 29, 2026
The structured-events rewrite (rails#55690) replaced the old render Start
subscriber with a new class that dropped the silenced? method rails#50751 had
added to its predecessor. Because the notifications Fanout treats
subscribers without silenced? as permanently active,
render_template.action_view and render_layout.action_view now run the
full instrumentation machinery on every render in every environment,
only for the emission to no-op inside ActiveSupport.event_reporter.debug
when debug mode is off (the default outside development).

Restoring silenced? - silencing whenever the event reporter is not in
debug mode, as the rails#50751 fix did for the log level - lets the
notification layer skip that work at the source. Behavior in debug mode
is unchanged.

Co-Authored-By: Claude Fable 5 <[email protected]>
nuclearspike added a commit to nuclearspike/rails that referenced this pull request Jul 30, 2026
The structured-events rewrite (rails#55690) replaced the old render Start
subscriber with a new class that dropped the silenced? method rails#50751 had
added to its predecessor. Because the notifications Fanout treats
subscribers without silenced? as permanently active,
render_template.action_view and render_layout.action_view now run the
full instrumentation machinery on every render in every environment,
only for the emission to no-op inside ActiveSupport.event_reporter.debug
when debug mode is off (the default outside development).

Restoring silenced? - silencing whenever the event reporter is not in
debug mode, as the rails#50751 fix did for the log level - lets the
notification layer skip that work at the source. Behavior in debug mode
is unchanged.

Co-Authored-By: Claude Fable 5 <[email protected]>
nuclearspike added a commit to nuclearspike/rails that referenced this pull request Jul 30, 2026
The structured-events rewrite (rails#55690) replaced the old render Start
subscriber with a new class that dropped the silenced? method rails#50751 had
added to its predecessor. Because the notifications Fanout treats
subscribers without silenced? as permanently active,
render_template.action_view and render_layout.action_view now run the
full instrumentation machinery on every render in every environment,
only for the emission to no-op inside ActiveSupport.event_reporter.debug
when debug mode is off (the default outside development).

Restoring silenced? - silencing whenever the event reporter is not in
debug mode, as the rails#50751 fix did for the log level - lets the
notification layer skip that work at the source. Behavior in debug mode
is unchanged.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants