Class: GrpcOpencensusInterceptor::ClientInterceptor
- Inherits:
-
GRPC::ClientInterceptor
- Object
- GRPC::ClientInterceptor
- GrpcOpencensusInterceptor::ClientInterceptor
- Defined in:
- lib/grpc_opencensus_interceptor/client_interceptor.rb
Instance Method Summary collapse
-
#initialize(span_context: nil, sampler: nil) ⇒ ClientInterceptor
constructor
A new instance of ClientInterceptor.
-
#request_response(request:, call:, method:, metadata:) ⇒ Object
Intercept a unary request response call.
Constructor Details
#initialize(span_context: nil, sampler: nil) ⇒ ClientInterceptor
Returns a new instance of ClientInterceptor.
8 9 10 11 12 |
# File 'lib/grpc_opencensus_interceptor/client_interceptor.rb', line 8 def initialize(span_context: nil, sampler: nil) @span_context = span_context || OpenCensus::Trace @sampler = sampler @serializer = OpenCensus::Trace::Formatters::Binary.new end |
Instance Method Details
#request_response(request:, call:, method:, metadata:) ⇒ Object
Intercept a unary request response call
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_opencensus_interceptor/client_interceptor.rb', line 22 def request_response(request:, call:, method:, metadata:) span_context = @span_context if span_context == OpenCensus::Trace && !span_context.span_context return yield end # NOTE: Use method as span name span_name = method span = span_context.start_span span_name, sampler: @sampler start_request span, method, begin grpc_ex = GRPC::Ok.new yield rescue StandardError => e grpc_ex = Util.to_grpc_ex(e) raise e ensure finish_request span, grpc_ex span_context.end_span span end end |