Instrumenters

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, finish, id, payload|
name # => String, name of the event (such as 'render' from above)
start # => Time, when the instrumented block started execution
finish # => Time, when the instrumented block ended execution
id # => String, unique ID for this notification
payload # => Hash, the payload
end

The block in the subscribe call gets the name of the event,
start timestamp, end timestamp, a string with a unique identifier for that
event (something like “535801666f04d0298cd6”), and a hash with the payload,
in that order.

If an exception happens during that particular instrumentation the payload
will have a key :exception with an array of two elements as
value: a string with the name of the exception class, and the exception
message.

As the previous example depicts, the class
ActiveSupport::Notifications::Event is able to take the
arguments as they come and provide an object-oriented interface to that
data.

It is also possible to pass an object as the second parameter passed to the
subscribe method instead of a block: