Sha256: 90835bc17a8a2b815ec1af7a86988eaf1acaf0dc772034d84b383244ef1fb341

Contents?: true

Size: 841 Bytes

Versions: 20

Compression:

Stored size: 841 Bytes

Contents

class CC::Service::Invocation
  class WithMetrics
    def initialize(invocation, statsd, prefix = nil)
      @invocation = invocation
      @statsd = statsd
      @prefix = prefix
    end

    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

    def success_key
      ["services.invocations", @prefix].compact.join('.')
    end

    def timing_key
      ["services.timing", @prefix].compact.join('.')
    end

    def error_key(ex)
      error_string = ex.class.name.underscore.gsub("/", "-")
      ["services.errors", @prefix, error_string].compact.join('.')
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
codeclimate-services-1.6.1 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.6.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.5.1 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.5.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.4.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.3.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.2.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.1.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.0.1 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-1.0.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.6.2 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.6.1 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.6.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.5.3 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.5.2 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.5.1 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.5.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.4.1 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.4.0 lib/cc/service/invocation/with_metrics.rb
codeclimate-services-0.3.0 lib/cc/service/invocation/with_metrics.rb