Class: Sentry::Gruf::ServerInterceptor

Inherits:
Gruf::Interceptors::ServerInterceptor
  • Object
show all
Defined in:
lib/sentry/gruf/server_interceptor.rb

Overview

Interceptor for Gruf wrapper of gRPC server. It handles all uncaught exceptions and sent them to the Sentry. Add this interceptor to the begining of interceptors stack.

Examples:

Use server interceptor

Gruf.configure do |config|
  config.interceptors.clear
  config.interceptors.use(Sentry::Gruf::ServerInterceptor)
end

Instance Method Summary collapse

Instance Method Details

#call { ... } ⇒ Object

Required method by Gruf interceptor specification.

Yields:

  • Perform request logic

See Also:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sentry/gruf/server_interceptor.rb', line 17

def call
  # make sure the current thread has a clean hub
  Sentry.clone_hub_to_current_thread

  Sentry.with_scope do |scope|
    scope.clear_breadcrumbs
    scope.set_transaction_name(request.service_key)
    scope.set_tags(
      grpc_method: request.method_key,
      grpc_request_class: request.request_class.name,
      grpc_service_key: request.service_key,
    )

    begin
      yield
    rescue Exception => e
      sensitive_grpc_codes = options[:sensitive_grpc_codes] || []
      raise if e.is_a?(GRPC::BadStatus) && !sensitive_grpc_codes.include?(e.code.to_s)

      ::Sentry::Gruf.capture_exception(e)

      raise
    end
  end
end