Class: Yabeda::AnyCable::Middleware

Inherits:
AnyCable::Middleware
  • Object
show all
Defined in:
lib/yabeda/anycable/middleware.rb

Overview

Instrumentation middleware that wraps every RPC command execution

Instance Method Summary collapse

Instance Method Details

#call(rpc_method_name, request, _metadata = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/yabeda/anycable/middleware.rb', line 9

def call(rpc_method_name, request,  = nil)
  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  (response = yield)
ensure
  elapsed = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started).round(4)
  status  = response.respond_to?(:status) ? response.status.to_s : "ERROR"
  command = request.respond_to?(:command) ? request.command : ""
  labels  = { method: rpc_method_name.to_s, status: status, command: command }
  ::Yabeda.anycable.rpc_call_count.increment(labels)
  ::Yabeda.anycable.rpc_call_runtime.measure(labels, elapsed)
end