Class: Gruf::Interceptors::Instrumentation::Statsd

Inherits:
ServerInterceptor show all
Defined in:
lib/gruf/interceptors/instrumentation/statsd.rb

Overview

Adds increment and timing stats to gRPC routes, pushing data to StatsD

Instance Attribute Summary

Attributes inherited from Base

#error, #options, #request

Instance Method Summary collapse

Methods included from Errors::Helpers

#fail!

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Gruf::Interceptors::Base

Instance Method Details

#callObject

Push data to StatsD, only doing so if a client is set



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gruf/interceptors/instrumentation/statsd.rb', line 26

def call
  unless client
    Gruf.logger.error 'Statsd module loaded, but no client configured!'
    return yield
  end

  client.increment(route_key)

  result = Gruf::Interceptors::Timer.time do
    yield
  end

  client.increment("#{route_key}.#{postfix(result.successful?)}")
  client.timing(route_key, result.elapsed)

  raise result.message unless result.successful?
  result.message
end