Skip to content
Newer
Older
100644 54 lines (45 sloc) 1.34 KB
4f2a04c @jeremy Notifications: extract central Notifier, cordon off the internal Fano…
jeremy authored Nov 28, 2009
1 require 'active_support/core_ext/module/delegation'
2
3 module ActiveSupport
4 module Notifications
5 class Instrumenter
45462c5 @josevalim Expose Instrumenter id in Notifications.
josevalim authored Jan 4, 2010
6 attr_reader :id
7
4f2a04c @jeremy Notifications: extract central Notifier, cordon off the internal Fano…
jeremy authored Nov 28, 2009
8 def initialize(notifier)
9 @id = unique_id
10 @notifier = notifier
11 end
12
7c3573f @josevalim Add instrument! to notifications which adds the result to the payload.
josevalim authored Jan 13, 2010
13 # Instrument the given block by measuring the time taken to execute it
a76c7e6 @josevalim Event should be aware if yielded block failed or not.
josevalim authored May 2, 2010
14 # and publish it. Notice that events get sent even if an error occurs
15 # in the passed-in block
ff0d842 @josevalim Revert the previous three commits.
josevalim authored Jul 25, 2010
16 def instrument(name, payload={})
17 started = Time.now
18
109d3ee @jaggederest Make notifications go off even when an error is raised, so that we ca…
jaggederest authored Apr 27, 2010
19 begin
ba8d89c Performance optimizations to handle cases of instrumentors that are n…
Carlhuda authored Jul 21, 2010
20 yield
a76c7e6 @josevalim Event should be aware if yielded block failed or not.
josevalim authored May 2, 2010
21 rescue Exception => e
22 payload[:exception] = [e.class.name, e.message]
23 raise e
109d3ee @jaggederest Make notifications go off even when an error is raised, so that we ca…
jaggederest authored Apr 27, 2010
24 ensure
ff0d842 @josevalim Revert the previous three commits.
josevalim authored Jul 25, 2010
25 @notifier.publish(name, started, Time.now, @id, payload)
109d3ee @jaggederest Make notifications go off even when an error is raised, so that we ca…
jaggederest authored Apr 27, 2010
26 end
4f2a04c @jeremy Notifications: extract central Notifier, cordon off the internal Fano…
jeremy authored Nov 28, 2009
27 end
28
29 private
30 def unique_id
31 SecureRandom.hex(10)
32 end
33 end
34
35 class Event
cfca559 @tenderlove convert duration to an attr_reader
tenderlove authored Jul 17, 2010
36 attr_reader :name, :time, :end, :transaction_id, :payload, :duration
4f2a04c @jeremy Notifications: extract central Notifier, cordon off the internal Fano…
jeremy authored Nov 28, 2009
37
75ba102 @josevalim Remove ActionView inline logging to ActiveSupport::Notifications and …
josevalim authored Dec 26, 2009
38 def initialize(name, start, ending, transaction_id, payload)
4f2a04c @jeremy Notifications: extract central Notifier, cordon off the internal Fano…
jeremy authored Nov 28, 2009
39 @name = name
40 @payload = payload.dup
41 @time = start
42 @transaction_id = transaction_id
43 @end = ending
cfca559 @tenderlove convert duration to an attr_reader
tenderlove authored Jul 17, 2010
44 @duration = 1000.0 * (@end - @time)
4f2a04c @jeremy Notifications: extract central Notifier, cordon off the internal Fano…
jeremy authored Nov 28, 2009
45 end
46
47 def parent_of?(event)
cfca559 @tenderlove convert duration to an attr_reader
tenderlove authored Jul 17, 2010
48 start = (time - event.time) * 1000
4f2a04c @jeremy Notifications: extract central Notifier, cordon off the internal Fano…
jeremy authored Nov 28, 2009
49 start <= 0 && (start + duration >= event.duration)
50 end
51 end
52 end
53 end
Something went wrong with that request. Please try again.