Class: Gruf::Instrumentation::Base
- Inherits:
-
Object
- Object
- Gruf::Instrumentation::Base
- Includes:
- Loggable
- Defined in:
- lib/gruf/instrumentation/base.rb
Overview
Base class for an instrumentation strategy. Define a call method to utilize functionality.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
Options Options to use when instrumenting the call.
-
#service ⇒ Gruf::Service
readonly
Service The service to instrument.
Instance Method Summary collapse
-
#call(_rc) ⇒ Object
abstract
Abstract method that is required for implementing an instrumentation strategy.
-
#initialize(service, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#method_key(call_signature, delimiter: '.') ⇒ String
Parse the method signature into a service.method name format.
-
#outer_around(call_signature, request, active_call, &_block) ⇒ Object
Hook into the outer_around call to time the request, and pass that to the call method.
-
#service_key ⇒ String
Returns the service name as a translated name separated by periods.
-
#setup ⇒ Object
Useful for setting up an instrumentation module post instantiation.
-
#success?(response) ⇒ Boolean
Was this call a success? If a response is a GRPC::BadStatus object, we assume that it was unsuccessful.
Methods included from Loggable
Constructor Details
#initialize(service, options = {}) ⇒ Base
Returns a new instance of Base.
36 37 38 39 40 |
# File 'lib/gruf/instrumentation/base.rb', line 36 def initialize(service, = {}) @service = service @options = setup end |
Instance Attribute Details
#options ⇒ Hash (readonly)
Returns options Options to use when instrumenting the call.
30 31 32 |
# File 'lib/gruf/instrumentation/base.rb', line 30 def @options end |
#service ⇒ Gruf::Service (readonly)
Returns service The service to instrument.
28 29 30 |
# File 'lib/gruf/instrumentation/base.rb', line 28 def service @service end |
Instance Method Details
#call(_rc) ⇒ Object
Abstract method that is required for implementing an instrumentation strategy.
65 66 67 |
# File 'lib/gruf/instrumentation/base.rb', line 65 def call(_rc) raise NotImplementedError end |
#method_key(call_signature, delimiter: '.') ⇒ String
Parse the method signature into a service.method name format
109 110 111 |
# File 'lib/gruf/instrumentation/base.rb', line 109 def method_key(call_signature, delimiter: '.') "#{service_key}#{delimiter}#{call_signature}" end |
#outer_around(call_signature, request, active_call, &_block) ⇒ Object
Hook into the outer_around call to time the request, and pass that to the call method
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/gruf/instrumentation/base.rb', line 78 def outer_around(call_signature, request, active_call, &_block) timed = Timer.time do yield end rc = RequestContext.new( service: service, request: request, response: timed.result, execution_time: timed.time, call_signature: call_signature, active_call: active_call ) call(rc) raise rc.response unless rc.success? rc.response end |
#service_key ⇒ String
Returns the service name as a translated name separated by periods
98 99 100 |
# File 'lib/gruf/instrumentation/base.rb', line 98 def service_key service.class.name.underscore.tr('/', '.') end |
#setup ⇒ Object
Useful for setting up an instrumentation module post instantiation
45 46 47 |
# File 'lib/gruf/instrumentation/base.rb', line 45 def setup # noop end |
#success?(response) ⇒ Boolean
Was this call a success? If a response is a GRPC::BadStatus object, we assume that it was unsuccessful
55 56 57 |
# File 'lib/gruf/instrumentation/base.rb', line 55 def success?(response) !response.is_a?(GRPC::BadStatus) end |