diff options
author | Justin George <justin.george@gmail.com> | 2010-04-27 14:13:47 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-05-02 22:45:53 +0200 |
commit | 109d3ee38d1c39f0e27bc827065427635d6396b2 (patch) | |
tree | d3acf513a62d3928e445fd79aa658fa2be56c461 /activesupport/lib/active_support | |
parent | 02028e529c97488b6c70cdbf66dc08c7fb2d36aa (diff) | |
download | rails-109d3ee38d1c39f0e27bc827065427635d6396b2.tar.gz rails-109d3ee38d1c39f0e27bc827065427635d6396b2.tar.bz2 rails-109d3ee38d1c39f0e27bc827065427635d6396b2.zip |
Make notifications go off even when an error is raised, so that we capture the underlying performance data [#4505 state:resolved]
This is important when trying to keep track of many layers of interrelated calls
i.e.:
ActiveRecord::Base.transaction do
MyModel.find(1) #ActiveRecord::NotFound
end # should capture the full time until the error propagation
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/notifications/instrumenter.rb | 10 |
1 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 f3d877efe7..ef3fdd1843 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -15,9 +15,13 @@ module ActiveSupport # and publish it. 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? + 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 private |