class CC::Service::Invocation::WithMetrics

Public Class Methods

new(invocation, statsd, prefix = nil) click to toggle source
# File lib/cc/service/invocation/with_metrics.rb, line 3
def initialize(invocation, statsd, prefix = nil)
  @invocation = invocation
  @statsd = statsd
  @prefix = prefix
end

Public Instance Methods

call() click to toggle source
# File lib/cc/service/invocation/with_metrics.rb, line 9
def call
  start_time = Time.now

  result = @invocation.call
  @statsd.increment(success_key)

  result
rescue => ex
  @statsd.increment(error_key(ex))
  raise ex
ensure
  duration = ((Time.now - start_time) * 1_000).round
  @statsd.timing(timing_key, duration)
end
error_key(ex) click to toggle source
# File lib/cc/service/invocation/with_metrics.rb, line 32
def error_key(ex)
  error_string = ex.class.name.underscore.tr("/", "-")
  ["services.errors", @prefix, error_string].compact.join(".")
end
success_key() click to toggle source
# File lib/cc/service/invocation/with_metrics.rb, line 24
def success_key
  ["services.invocations", @prefix].compact.join(".")
end
timing_key() click to toggle source
# File lib/cc/service/invocation/with_metrics.rb, line 28
def timing_key
  ["services.timing", @prefix].compact.join(".")
end