Class: Gruf::Rollbar::ServerInterceptor

Inherits:
Interceptors::ServerInterceptor
  • Object
show all
Includes:
ErrorParser
Defined in:
lib/gruf/rollbar/server_interceptor.rb

Overview

Intercepts inbound calls to provide Rollbar error reporting

Instance Method Summary collapse

Methods included from ErrorParser

#code_for, #error?, #error_classes

Instance Method Details

#call(&_block) ⇒ Object

Handle the gruf around hook and capture errors



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gruf/rollbar/server_interceptor.rb', line 14

def call(&_block)
  return yield if Gruf::Rollbar.ignore_methods.include?(request.method_name)

  begin
    yield
  rescue StandardError, GRPC::BadStatus => e
    if error?(e) # only capture
      ::Rollbar.scoped({
                         grpc_method: request.method_key,
                         grpc_request_class: request.request_class.name,
                         grpc_service_key: request.service_key,
                         grpc_error_code: code_for(e),
                         grpc_error_class: e.class.name
                       }) do
        ::Rollbar.error(e)
      end
    end
    raise # passthrough
  end
end