Class: Griffin::Interceptors::Server::ScoutApmInterceptor
- Inherits:
-
GRPC::ServerInterceptor
- Object
- GRPC::ServerInterceptor
- Griffin::Interceptors::Server::ScoutApmInterceptor
- Defined in:
- lib/griffin/interceptors/server/scout_apm_interceptor.rb
Constant Summary collapse
- LAYER_TYPE =
Specify the controller layer so that the transaction gets categorized as a web transaction.
'Controller'
Instance Method Summary collapse
-
#initialize(ignored_services: [], sampling_rate: 1.0) ⇒ ScoutApmInterceptor
constructor
A new instance of ScoutApmInterceptor.
- #request_response(request: nil, call: nil, method: nil) ⇒ Object
Constructor Details
#initialize(ignored_services: [], sampling_rate: 1.0) ⇒ ScoutApmInterceptor
Returns a new instance of ScoutApmInterceptor.
15 16 17 18 |
# File 'lib/griffin/interceptors/server/scout_apm_interceptor.rb', line 15 def initialize(ignored_services: [], sampling_rate: 1.0) @ignored_services = ignored_services.map(&:service_name) @sampling_rate = sampling_rate.to_f end |
Instance Method Details
#request_response(request: nil, call: nil, method: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/griffin/interceptors/server/scout_apm_interceptor.rb', line 20 def request_response(request: nil, call: nil, method: nil) service_name = call.service_name method_name = method.name return yield if rand > @sampling_rate || @ignored_services.include?(service_name) layer = ScoutApm::Layer.new(LAYER_TYPE, "#{service_name}/#{method_name}") req = ScoutApm::RequestManager.lookup req.start_layer(layer) req.annotate_request(uri: "/#{service_name}/#{method_name}") ScoutApm::Context.add( request_id: call.['x-request-id'], user_agent: call.['user-agent'], ) begin yield rescue => e req.error! raise e ensure req.stop_layer end end |