diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 3117fa49a0f72d6e81d101665c834f194b62b6ed..cee1e57c93100f9ac5e33d68d6e71a7c38e99d15 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -510,4 +510,10 @@ *Logan Leger* +* Adds `:exception_object` key to ActiveSupport::Notifications::Instrumenter payload when an exception is raised + + Adds new key/value pair to payload when an exception is raised: e.g. `:exception_object => #` + + *Ryan T. Hosford* + Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activesupport/CHANGELOG.md) for previous changes. diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 67f2ee1a7fcacc2c0a245b9f779ea8c69c4d2d41..91f94cb2d7ff9836c5d908f492a10129620dc460 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -21,6 +21,7 @@ def instrument(name, payload={}) yield payload rescue Exception => e payload[:exception] = [e.class.name, e.message] + payload[:exception_object] = e raise e ensure finish_with_state listeners_state, name, payload diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index d9cc392ac92d486e28bb9e30a04c977fe358df8e..1cb17e619734e526bee93199e9661a23a7f95716 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -232,7 +232,7 @@ def test_instrument_publishes_when_exception_is_raised assert_equal 1, @events.size assert_equal Hash[:payload => "notifications", - :exception => ["RuntimeError", "FAIL"]], @events.last.payload + :exception => ["RuntimeError", "FAIL"], :exception_object => e], @events.last.payload end def test_event_is_pushed_even_without_block