diff options
-rw-r--r-- | activesupport/lib/active_support/notifications/instrumenter.rb | 8 | ||||
-rw-r--r-- | activesupport/test/notifications_test.rb | 2 |
2 files changed, 7 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index ef3fdd1843..7e89402822 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -12,14 +12,16 @@ module ActiveSupport 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 begin yield(payload) if block_given? + rescue Exception => e + payload[:exception] = [e.class.name, e.message] + raise e ensure - # Notify in an ensure block so that we can be certain end - # events get sent even if an error occurs in the passed-in block @notifier.publish(name, time, Time.now, @id, payload) end end diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 251380a0d5..e11de5f67a 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -179,6 +179,8 @@ module Notifications drain assert_equal 1, @events.size + assert_equal Hash[:payload => "notifications", + :exception => ["RuntimeError", "FAIL"]], @events.last.payload end def test_event_is_pushed_even_without_block |