Repository navigation
Structured event subscribers - #55690
Conversation
233c317 to
c3a1b91
Compare
| end | ||
|
|
||
| def rails_root # :doc: | ||
| @root ||= "#{Rails.try(:root)}/" |
There was a problem hiding this comment.
This might be a bit undesirable. The log subscriber waits until a logger is set, but the structured event subscriber doesn't need to so things get triggered early enough that Rails sometimes doesn't have root defined yet. Generally, we should not be referencing Rails at all here, and I want to work on injecting the root here in a cleaner way when I consolidate the notification subscribers. But, I can try to to do that earlier if we feel strongly about this being bad.
|
Looks like there's some CI failures I need to look at in Action View and the base class tests. Will do that ASAP. |
3ad8ba5 to
f8b663a
Compare
| exception_message: exception.message, | ||
| mail: event.payload[:mail], | ||
| ) | ||
| elsif event.payload[:perform_deliveries] |
There was a problem hiding this comment.
Why have separate events for what was the same notficiation?
https://edgeguides.rubyonrails.org/active_support_instrumentation.html#deliver-action-mailer
Are we going to publicly document these events, and their payloads (as stable) as their AS::Notification counterparts?
There was a problem hiding this comment.
- We should document these somewhere, yes. I'll look into that. There's no guides page yet. Given that, I think we should add it in a followup patch.
- We do this in the job subscriber too. The notification is too general, and I think it makes more sense to emit specific events in these cases. I'll think about consolidating them to one event, but I don't want to include an error keys in the payload unless there's an actual error, for example.
There was a problem hiding this comment.
I think a new guide next to the AS instrumentation one "Active Support Structured Events" could make sense.
But once we document them, making changes are more difficult, so good to get feedback on the events being added here first. Maybe they could stay experimental and undocumented for now?
The other thing, now we have essentially two places to maintain the same basic "event" from Rails. So if someone wants to add a new field to the payload to sql.active_record (for example) -- they now have to do it in multiple places, which can be a source for confusion and bugs.
How we have CI to tell us if a new config flag is missing from the configuring guide, I always thought it'd be nice to have for notifications as well, that might help.
There is some benefit to keeping the event names and payloads consistent between the two, but I also can appreciate the chance to make them better before people are depending on them. I don't have a strong opinion on this type of change, just wanted to call it out as a question.
Keep up the good work! :)
There was a problem hiding this comment.
Changing events in two places is unfortunate, but because notification events can have non-serializable data, and structured events should be serializable, there's likely going to be a translation layer needed for all of these regardless. In terms of the original discussion about the multiple IFs, I will refactor these instances to a singular event being emitted with variable payload content to mirror related notification events.
Thanks again for all your feedback!
|
What would be the preferred way to turn these off if you don't need them? They seem to be like other LogSubscribers so AS::Subscriber.subscibers. 🤔 Are there any concern of overhead by essentially doubling all the notification events? Sorry just random thoughts popped into my head looking at this, I think it will take some time to review the events for each framework but it's nice they are all in one PR. Thanks for working on this! |
I tried doing this already by disabling method calls for debug mode events with |
e629953 to
0a3763a
Compare
Currently, structured events for Active Record doesn't emit on v8.1. This is because `active_record/structured_event_subscriber` isn't loaded. I guess we just forgot to require it in rails#55690. In `main` branch, this was already fixed by rails#55900. I think we should fix this on 8.1 because we mentioned structured events for Active Record on CHANGELOG. https://github.com/rails/rails/blob/8-1-stable/activerecord/CHANGELOG.md#rails-810-october-22-2025
Currently, structured events for Active Record doesn't emit on v8.1. This is because `active_record/structured_event_subscriber` isn't loaded. I guess we just forgot to require it in rails#55690. In `main` branch, this was already fixed by rails#55900. I think we should fix this on 8.1 because we mentioned structured events for Active Record on CHANGELOG. https://github.com/rails/rails/blob/8-1-stable/activerecord/CHANGELOG.md#rails-810-october-22-2025
Currently, structured events for Active Record doesn't emit on v8.1. This is because `active_record/structured_event_subscriber` isn't loaded. I guess we just forgot to require it in rails#55690. In `main` branch, this was already fixed by rails#55900. I think we should fix this on 8.1 because we mentioned structured events for Active Record on CHANGELOG. https://github.com/rails/rails/blob/8-1-stable/activerecord/CHANGELOG.md#rails-810-october-22-2025
Currently, structured events for Active Record doesn't emit on v8.1. This is because `active_record/structured_event_subscriber` isn't loaded. I guess we just forgot to require it in rails#55690. In `main` branch, this was already fixed by rails#55900. I think we should fix this on 8.1 because we mentioned structured events for Active Record on CHANGELOG. https://github.com/rails/rails/blob/8-1-stable/activerecord/CHANGELOG.md#rails-810-october-22-2025
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
In Rails 8.2, SQL logging was refactored with a new pipeline: Notifications → StructuredEventSubscriber → EventReporter → LogSubscriber (rails/rails#55690, rails/rails#55900). Both StructuredEventSubscriber and LogSubscriber have their own IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]. The existing spec_helper only patched LogSubscriber's copy, but SCHEMA queries are now filtered upstream at StructuredEventSubscriber before they ever reach LogSubscriber. Since all oracle-enhanced schema methods (table_comment, column_comment, foreign_keys, column_definitions, indexes, etc.) use "SCHEMA" as the query name, none of their SQL appeared in the test logger, causing 12 test failures. Co-Authored-By: Claude Opus 4.6 <[email protected]>
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]>
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]>
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]>
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]>
Motivation / Background
This Pull Request has been created to add structured events for framework notifications via the use of
ActiveSupport::StructuredEventSubscribersubclasses. Events may be emitted with the#emit_eventor#emit_debug_eventmethods like this, similar to a traditionalLogSubscriber:Detail
This Pull Request adds structured event subscribers for each framework library that has log subscribers for notifications. The idea is to mirror structured events for each existing framework log subscriber.
Additional information
Eventually, we would like to unify notification subscribing and emit logs for these structured events (instead of maintaining separate log subscribers), and that will happen in a followup change. For now, this is focused on adding support for events and minimizing the set of changes as to not break anything.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]