Class: Thrift::Metrics::Middleware::Timing

Inherits:
Object
  • Object
show all
Defined in:
lib/thrift/metrics.rb

Class Method Summary collapse

Class Method Details

.instrument(name, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/thrift/metrics.rb', line 20

def instrument(name, &block)
  t0 = Time.now

  begin
    r = block.call
    send_duration name, t0
    r
  rescue => e
    send_duration name, t0
    raise e
  end
end

.send_duration(name, t0) ⇒ Object



13
14
15
16
17
18
# File 'lib/thrift/metrics.rb', line 13

def send_duration(name, t0)
  Metrics.client.timing(
    "#{name}.duration",
    ((Time.now - t0) * 1_000).to_i
  )
end