Class: OpenTelemetry::Instrumentation::Gruf::Interceptors::Server
- Inherits:
-
Gruf::Interceptors::ServerInterceptor
- Object
- Gruf::Interceptors::ServerInterceptor
- OpenTelemetry::Instrumentation::Gruf::Interceptors::Server
- Defined in:
- lib/opentelemetry/instrumentation/gruf/interceptors/server.rb
Overview
Server is a Gruf server interceptor that creates an OpenTelemetry span for each inbound gRPC call, extracting trace context from request metadata
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
15 16 17 18 19 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/opentelemetry/instrumentation/gruf/interceptors/server.rb', line 15 def call return yield unless Gruf::Instrumentation.instance.installed? method = request.method_name return yield if instrumentation_config[:grpc_ignore_methods_on_server].include?(method) service_name = request.service.service_name.to_s method_name = request.method_key.to_s route = "/#{service_name}/#{method_name.camelize}" = request.active_call. attributes = { OpenTelemetry::SemanticConventions::Trace::RPC_SYSTEM => 'grpc', OpenTelemetry::SemanticConventions::Trace::RPC_SERVICE => service_name, OpenTelemetry::SemanticConventions::Trace::RPC_METHOD => method_name, OpenTelemetry::SemanticConventions::Trace::PEER_SERVICE => instrumentation_config[:peer_service], 'net.sock.peer.addr' => request.active_call.instance_variable_get(:@wrapped)&.peer }.compact attributes.merge!((.transform_keys(&:to_s))) extracted_context = OpenTelemetry.propagation.extract() OpenTelemetry::Context.with_current(extracted_context) do instrumentation_tracer.in_span(route, attributes: attributes, kind: OpenTelemetry::Trace::SpanKind::SERVER) do |span| yield.tap do span&.set_attribute(OpenTelemetry::SemanticConventions::Trace::RPC_GRPC_STATUS_CODE, 0) end end end end |