module ActiveSupport::Notifications
def instrument(name, payload = {})
def instrument(name, payload = {}) if notifier.listening?(name) instrumenter.instrument(name, payload) { yield payload if block_given? } else yield payload if block_given? end end
def instrumenter
def instrumenter InstrumentationRegistry.instance.instrumenter_for(notifier) end
def publish(name, *args)
def publish(name, *args) notifier.publish(name, *args) end
def subscribe(*args, &block)
@event = event
ActiveSupport::Notifications.subscribe(/render/) do |event|
it will yield an event object to the block:
If the block passed to the method only takes one parameter,
end
payload # => Hash, the payload
id # => String, unique ID for the instrumenter that fired the event
finish # => Time, when the instrumented block ended execution
start # => Time, when the instrumented block started execution
name # => String, name of the event (such as 'render' from above)
ActiveSupport::Notifications.subscribe('render') do |name, start, finish, id, payload|
The +block+ will receive five parameters with information about the event:
end
@event = ActiveSupport::Notifications::Event.new(*args)
ActiveSupport::Notifications.subscribe(/render/) do |*args|
names, or by passing a Regexp to match all events that match a pattern.
You can subscribe to events by passing a String to match exact event
Subscribe to a given event name with the passed +block+.
def subscribe(*args, &block) notifier.subscribe(*args, &block) end
def subscribed(callback, *args, &block)
def subscribed(callback, *args, &block) subscriber = subscribe(*args, &callback) yield ensure unsubscribe(subscriber) end
def unsubscribe(subscriber_or_name)
def unsubscribe(subscriber_or_name) notifier.unsubscribe(subscriber_or_name) end