Class: GrpcOpencensusInterceptor::ServerInterceptor
- Inherits:
-
GRPC::ServerInterceptor
- Object
- GRPC::ServerInterceptor
- GrpcOpencensusInterceptor::ServerInterceptor
- Defined in:
- lib/grpc_opencensus_interceptor/server_interceptor.rb,
lib/grpc_opencensus_interceptor/server_interceptor/span_modifier.rb
Defined Under Namespace
Classes: SpanModifier
Instance Method Summary collapse
-
#initialize(exporter: nil, span_modifier: nil) ⇒ ServerInterceptor
constructor
takes span, request, call, method as its parameters.
-
#request_response(request:, call:, method:) ⇒ Object
Intercept a unary request response call.
Constructor Details
#initialize(exporter: nil, span_modifier: nil) ⇒ ServerInterceptor
takes span, request, call, method as its parameters.
12 13 14 15 16 |
# File 'lib/grpc_opencensus_interceptor/server_interceptor.rb', line 12 def initialize(exporter: nil, span_modifier: nil) @exporter = exporter || OpenCensus::Trace.config.exporter @span_modifier = span_modifier @deserializer = OpenCensus::Trace::Formatters::Binary.new end |
Instance Method Details
#request_response(request:, call:, method:) ⇒ Object
Intercept a unary request response call.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/grpc_opencensus_interceptor/server_interceptor.rb', line 25 def request_response(request:, call:, method:) context_bin = call.[Util::OPENCENSUS_TRACE_BIN_KEY] if context_bin context = deserialize(context_bin) else context = nil end OpenCensus::Trace.start_request_trace( trace_context: context, same_process_as_parent: false) do |span_context| begin OpenCensus::Trace.in_span get_name(method) do |span| modify_span(span, request, call, method) start_request(span, call, 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) end end ensure @exporter.export span_context.build_contained_spans end end end |