Class: GrpcInterceptors::Server::OpenTelemetryTracingInstrument

Inherits:
GRPC::ServerInterceptor
  • Object
show all
Defined in:
lib/grpc_interceptors/server/open_telemetry_tracing_instrument.rb

Overview

Instance Method Summary collapse

Instance Method Details

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/grpc_interceptors/server/open_telemetry_tracing_instrument.rb', line 9

def request_response(request: nil, call: nil, method: nil)
  parent_context = OpenTelemetry.propagation.extract(call.)
  route_name = GrpcHelper.route_name(method)
  attributes = tracing_attributes(method)
  kind = OpenTelemetry::Trace::SpanKind::SERVER
  span = GrpcHelper.tracer.start_span(
    route_name,
    with_parent: parent_context,
    attributes: attributes,
    kind: kind
  )

  yield

  span.finish
rescue StandardError => e
  OpenTelemetry.handle_error(exception: e)

  raise e
ensure
  span.finish if span.recording?
end