aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorBogdan <bogdanvlviv@gmail.com>2018-12-17 10:25:55 +0200
committerRyuta Kamizono <kamipo@gmail.com>2018-12-17 17:25:55 +0900
commitfdb27193087c23ea2e7a0e8f6f035c47f274dbf7 (patch)
tree8c085967f00043ae143ec9f39414501830240925 /guides
parentce48b5a366482d4b4c4c053e1e39e79d71987197 (diff)
downloadrails-fdb27193087c23ea2e7a0e8f6f035c47f274dbf7.tar.gz
rails-fdb27193087c23ea2e7a0e8f6f035c47f274dbf7.tar.bz2
rails-fdb27193087c23ea2e7a0e8f6f035c47f274dbf7.zip
Extend documentation of `ActiveSupport::Notifications.subscribe` (#34721)
* Extend documentation of `ActiveSupport::Notifications.subscribe` Add mention that a block with only one argument passed to the method will yield an event object. Related to #33451 * Emphasize that `SubscribeEventObjects` is a test class by adding suffix `Test`
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_support_instrumentation.md14
1 files changed, 13 insertions, 1 deletions
diff --git a/guides/source/active_support_instrumentation.md b/guides/source/active_support_instrumentation.md
index 64db141381..5e68b3f400 100644
--- a/guides/source/active_support_instrumentation.md
+++ b/guides/source/active_support_instrumentation.md
@@ -648,6 +648,18 @@ ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*a
end
```
+You may also pass block with only one argument, it will yield an event object to the block:
+
+```ruby
+ActiveSupport::Notifications.subscribe "process_action.action_controller" do |event|
+ event.name # => "process_action.action_controller"
+ event.duration # => 10 (in milliseconds)
+ event.payload # => {:extra=>information}
+
+ Rails.logger.info "#{event} Received!"
+end
+```
+
Most times you only care about the data itself. Here is a shortcut to just get the data.
```ruby
@@ -672,7 +684,7 @@ Creating custom events
Adding your own events is easy as well. `ActiveSupport::Notifications` will take care of
all the heavy lifting for you. Simply call `instrument` with a `name`, `payload` and a block.
The notification will be sent after the block returns. `ActiveSupport` will generate the start and end times
-and add the instrumenter's unique ID. All data passed into the `instrument` call will make
+and add the instrumenter's unique ID. All data passed into the `instrument` call will make
it into the payload.
Here's an example: