lib/active_support/notifications/instrumenter.rb in activesupport-3.0.0.beta3 vs lib/active_support/notifications/instrumenter.rb in activesupport-3.0.0.beta4
- old
+ new
@@ -10,15 +10,21 @@
@id = unique_id
@notifier = notifier
end
# Instrument the given block by measuring the time taken to execute it
- # and publish it.
+ # and publish it. Notice that events get sent even if an error occurs
+ # in the passed-in block
def instrument(name, payload={})
time = Time.now
- result = yield(payload) if block_given?
- @notifier.publish(name, time, Time.now, @id, payload)
- result
+ begin
+ yield(payload) if block_given?
+ rescue Exception => e
+ payload[:exception] = [e.class.name, e.message]
+ raise e
+ ensure
+ @notifier.publish(name, time, Time.now, @id, payload)
+ end
end
private
def unique_id
SecureRandom.hex(10)