Class: ActiveSupport::Notifications::Instrumenter
- Defined in:
- lib/active_support/notifications/instrumenter.rb
Overview
Instrumenters are stored in a thread local.
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#finish(name, payload) ⇒ Object
Send a finish notification with
name
andpayload
. -
#initialize(notifier) ⇒ Instrumenter
constructor
A new instance of Instrumenter.
-
#instrument(name, payload = {}) ⇒ Object
Instrument the given block by measuring the time taken to execute it and publish it.
-
#start(name, payload) ⇒ Object
Send a start notification with
name
andpayload
.
Constructor Details
#initialize(notifier) ⇒ Instrumenter
Returns a new instance of Instrumenter.
9 10 11 12 |
# File 'lib/active_support/notifications/instrumenter.rb', line 9 def initialize(notifier) @id = unique_id @notifier = notifier end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/active_support/notifications/instrumenter.rb', line 7 def id @id end |
Instance Method Details
#finish(name, payload) ⇒ Object
Send a finish notification with name
and payload
.
35 36 37 |
# File 'lib/active_support/notifications/instrumenter.rb', line 35 def finish(name, payload) @notifier.finish name, @id, payload end |
#instrument(name, payload = {}) ⇒ Object
Instrument the given block by measuring the time taken to execute it and publish it. Notice that events get sent even if an error occurs in the passed-in block.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/active_support/notifications/instrumenter.rb', line 17 def instrument(name, payload={}) start name, payload begin yield payload rescue Exception => e payload[:exception] = [e.class.name, e.] raise e ensure finish name, payload end end |
#start(name, payload) ⇒ Object
Send a start notification with name
and payload
.
30 31 32 |
# File 'lib/active_support/notifications/instrumenter.rb', line 30 def start(name, payload) @notifier.start name, @id, payload end |