Class: GrpcNewrelicInterceptor::ServerInterceptor

Inherits:
GRPC::ServerInterceptor
  • Object
show all
Defined in:
lib/grpc_newrelic_interceptor/server_interceptor.rb

Defined Under Namespace

Classes: Request

Instance Method Summary collapse

Constructor Details

#initialize(ignored_services: [], params_filter: nil) ⇒ ServerInterceptor

Returns a new instance of ServerInterceptor.

Parameters:

  • ignored_services (<#service_name>) (defaults to: [])
  • params_filter (#filter, nil) (defaults to: nil)


10
11
12
13
# File 'lib/grpc_newrelic_interceptor/server_interceptor.rb', line 10

def initialize(ignored_services: [], params_filter: nil)
  @ignored_services = Set.new(ignored_services.map(&:service_name))
  @params_filter    = params_filter
end

Instance Method Details

#request_response(request:, call:, method:) ⇒ Object

Intercept a unary request response call.

Parameters:

  • request (Object)
  • call (GRPC::ActiveCall::SingleReqView)
  • method (Method)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/grpc_newrelic_interceptor/server_interceptor.rb', line 22

def request_response(request:, call:, method:)
  return yield if !newrelic_enabled?

  service_name = get_service_name(method)

  return yield if @ignored_services.include?(service_name)

  # NewRelic::Agent::Tracer.in_transaction is introduced in Newrelic v6.0.0.
  # We can use it for custom instrumentation.
  # cf. https://github.com/newrelic/rpm/blob/6.0.0.351/lib/new_relic/agent/tracer.rb#L42-L55
  transaction_options = {
    partial_name: get_partial_name(method),
    category:     :rack,
    options:      {
      request:         get_request(method, call),
      filtered_params: filter(request.to_h),
    }
  }
  NewRelic::Agent::Tracer.in_transaction(**transaction_options) do
    yield
  end
end