class ActiveSupport::StructuredEventSubscriber

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.