class Yabeda::AnyCable::Middleware

Instrumentation middleware that wraps every RPC command execution

Public Instance Methods

call(rpc_method_name, request, _metadata = nil) { || ... } click to toggle source
# File lib/yabeda/anycable/middleware.rb, line 9
def call(rpc_method_name, request, _metadata = nil)
  started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
  (response = yield)
ensure
  elapsed = (Process.clock_gettime(Process::CLOCK_MONOTONIC) - started).round(4)
  labels = { method: rpc_method_name.to_s, status: response.status.to_s }
  labels[:command] = request.respond_to?(:command) ? request.command : ""
  ::Yabeda.anycable.rpc_call_count.increment(labels)
  ::Yabeda.anycable.rpc_call_runtime.measure(labels, elapsed)
end