Active Support Structured Event Subscriber¶ ↑
ActiveSupport::StructuredEventSubscriber consumes ActiveSupport::Notifications in order to emit structured events via Rails.event.
An example would be the Action Controller structured event subscriber, responsible for emitting request processing events:
module ActionController class StructuredEventSubscriber < ActiveSupport::StructuredEventSubscriber attach_to :action_controller def start_processing(event) emit_event("controller.request_started", controller: event.payload[:controller], action: event.payload[:action], format: event.payload[:format] ) end end end
After configured, whenever a "start_processing.action_controller" notification is published, it will properly dispatch the event (ActiveSupport::Notifications::Event) to the start_processing method. The subscriber can then emit a structured event via the emit_event method.
- C
- E
- N
- S
Class Public methods
new() Link
Instance Public methods
call(event) Link
emit_debug_event(name, payload = nil, caller_depth: 1, **kwargs) Link
Like emit_event, but only emits when the event reporter is in debug mode
# File activesupport/lib/active_support/structured_event_subscriber.rb, line 92 def emit_debug_event(name, payload = nil, caller_depth: 1, **kwargs) ActiveSupport.event_reporter.debug(name, payload, caller_depth: caller_depth + 1, filter_payload: false, **kwargs) rescue => e handle_event_error(name, e) end
emit_event(name, payload = nil, caller_depth: 1, **kwargs) Link
Emit a structured event via Rails.event.notify.
Arguments¶ ↑
-
name- The event name as a string or symbol -
payload- The event payload as a hash or object -
caller_depth- Stack depth for source location (default: 1) -
kwargs- Additional payload data merged with the payload hash
# File activesupport/lib/active_support/structured_event_subscriber.rb, line 85 def emit_event(name, payload = nil, caller_depth: 1, **kwargs) ActiveSupport.event_reporter.notify(name, payload, caller_depth: caller_depth + 1, filter_payload: false, **kwargs) rescue => e handle_event_error(name, e) end
emitting?(name) Link
Whether any event reporter subscriber would currently consume an event with the given name. Handlers can use this to skip building payloads for events that would go nowhere.