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

#call(&block) ⇒ Object

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



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

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

  client.increment(route_key)

  result = Gruf::Interceptors::Timer.time(&block)

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

  raise result.message unless result.successful?

  result.message
end