Class: Clepsydra::Instrumenter

Inherits:
Object
  • Object
show all
Defined in:
lib/clepsydra/instrumenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notifier) ⇒ Instrumenter

Returns a new instance of Instrumenter.



7
8
9
10
# File 'lib/clepsydra/instrumenter.rb', line 7

def initialize(notifier)
  @id = "instrumenter_#{Clepsydra::TokenProvider.generate}"
  @notifier = notifier
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/clepsydra/instrumenter.rb', line 5

def id
  @id
end

Instance Method Details

#finish(event_name, event_id, payload) ⇒ Object



29
30
31
# File 'lib/clepsydra/instrumenter.rb', line 29

def finish(event_name, event_id, payload)
  @notifier.finish(event_name, event_id, @id, payload)
end

#instrument(event_name, payload = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/clepsydra/instrumenter.rb', line 12

def instrument(event_name, payload = {})
  event_id = start(event_name)

  yield payload if block_given?
rescue Exception => e
  payload[:exception] = e
  payload[:exception_message] = e.inspect

  raise e
ensure
  finish(event_name, event_id, payload)
end

#start(event_name) ⇒ Object



25
26
27
# File 'lib/clepsydra/instrumenter.rb', line 25

def start(event_name)
  @notifier.start(event_name, "event_#{Clepsydra::TokenProvider.generate}")
end