diff options
author | Guilherme Mansur <guilherme.mansur@shopify.com> | 2019-05-21 17:07:27 -0400 |
---|---|---|
committer | Guilherme Mansur <guilherme.mansur@shopify.com> | 2019-05-22 14:11:03 -0400 |
commit | 218f0777d6abf1b2f933e44bd08f75f3d28c75ca (patch) | |
tree | 273f446a349d25bd7a9d899d5a90d5488e3e7a8d /activesupport/lib/active_support/notifications | |
parent | 3453c5d4c0b54fc2a117a09ff4d5964110f5fbe8 (diff) | |
download | rails-218f0777d6abf1b2f933e44bd08f75f3d28c75ca.tar.gz rails-218f0777d6abf1b2f933e44bd08f75f3d28c75ca.tar.bz2 rails-218f0777d6abf1b2f933e44bd08f75f3d28c75ca.zip |
Merge payload for EventObject subscribers
When instrumenting a block of code like:
```ruby
ActiveSupport::Notifications.instrument("process_action.action_controller", raw_paylaod) do |payload|
payload[:view_runtime] = render_view
end
```
If we use an evented subscriber like so:
``` ruby
ActiveSupport::Notifications.subscribe("process_action.action_controller", raw_payload) do |event|
assert event.payload[:view_runtime]
end
```
The code breaks because the underlying EventObject's payload does not have the
`:view_runtime` key added during instrumentation.
This is because the `EventedObject` subscriber calls the `finish` method with the
`payload` of the event at the time it was pushed into the stack, before the
block executes, but we want to call `finish` with the `payload` after the
instrument block executes this way if the `payload` was modified during the block
we have access to it. This is consistent with the other types of subscribers
who don't have this bug.
Diffstat (limited to 'activesupport/lib/active_support/notifications')
-rw-r--r-- | activesupport/lib/active_support/notifications/fanout.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/notifications/instrumenter.rb | 3 |
2 files changed, 3 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index c37bec4ee5..97fe5bb09b 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -218,6 +218,7 @@ module ActiveSupport def finish(name, id, payload) stack = Thread.current[:_event_stack] event = stack.pop + event.payload = payload event.finish! @delegate.call event end diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 12546511a8..6ce5aa1af4 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -53,7 +53,8 @@ module ActiveSupport end class Event - attr_reader :name, :time, :end, :transaction_id, :payload, :children + attr_reader :name, :time, :end, :transaction_id, :children + attr_accessor :payload def self.clock_gettime_supported? # :nodoc: defined?(Process::CLOCK_PROCESS_CPUTIME_ID) && |