Ruby rails: notifications
From wikinotes
Documentation
instrumentation docs https://guides.rubyonrails.org/active_support_instrumentation.html#introduction-to-instrumentation
Basics
ActiveSupport::Notifications.subscribe("") do |name, started, finished, unique_id, data| puts name, started, finished, unique_id, data end # name: name of event (ex: 'process_action.action_controller') # started: Time # finished: Time # unique_id: # data:
ActiveSupport::Notifications.subscribe("process_action.action_controller") # explicit event-name ActiveSupport::Notifications.subscribe(/process_action/) # regex match event-name ActiveSupport::Notifications.monotonic_subscribe(/process_action/) # incl. leap/skipped seconds in start/endThere are several builtin events. See rails framework hooks.
Custom Events
ActiveSupport::Notifications.instrument("my.custom.event", param1: 1, param2: 2) # all keys are recorded as data