Notifications ActiveSupport::Notifications provides an instrumentation API for Ruby."> Notifications ActiveSupport::Notifications provides an instrumentation API for Ruby.">

Notifications

ActiveSupport::Notifications provides an instrumentation API for Ruby.

Instrumenters

To instrument an event you just need to do:

ActiveSupport::Notifications.instrument('render', extra: :information) do
  render plain: 'Foo'
end

That first executes the block and then notifies all subscribers once done.

In the example above render is the name of the event, and the rest is called the payload. The payload is a mechanism that allows instrumenters to pass extra information to subscribers. Payloads consist of a hash whose contents are arbitrary and generally depend on the event.

Subscribers

You can consume those events and the information they provide by registering a subscriber.

ActiveSupport::Notifications.subscribe('render') do |name, start, fin