Sha256: c85cb34760c6c25b14400a2a1763c30c8cb83dc2345d103c9bcdf9abe125c701

Contents?: true

Size: 1.74 KB

Versions: 27

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

# Disable the UnusedMethodArgument linter, since we need to declare the kwargs
# in the methods, but we don't actually use them.

require "opentracing"
require "grpc"

module Labkit
  module Tracing
    module GRPC
      # GRPCServerInterceptor is a server-side GRPC interceptor
      # for instrumenting GRPC calls with distributed tracing
      # in a GRPC Ruby server
      class ServerInterceptor < ::GRPC::ServerInterceptor
        include Labkit::Correlation::GRPC::GRPCCommon

        def request_response(request: nil, call: nil, method: nil)
          wrap_with_tracing(call, method, "unary") do
            yield
          end
        end

        def client_streamer(call: nil, method: nil)
          wrap_with_tracing(call, method, "client_stream") do
            yield
          end
        end

        def server_streamer(request: nil, call: nil, method: nil)
          wrap_with_tracing(call, method, "server_stream") do
            yield
          end
        end

        def bidi_streamer(requests: nil, call: nil, method: nil)
          wrap_with_tracing(call, method, "bidi_stream") do
            yield
          end
        end

        private

        def wrap_with_tracing(call, method, grpc_type)
          context = TracingUtils.tracer.extract(OpenTracing::FORMAT_TEXT_MAP, call.metadata)
          method_name = "/#{rpc_split(method).join("/")}"
          tags = {
            "component" => "grpc",
            "span.kind" => "server",
            "grpc.method" => method_name,
            "grpc.type" => grpc_type,
          }

          TracingUtils.with_tracing(operation_name: "grpc:#{method_name}", child_of: context, tags: tags) do |_span|
            yield
          end
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
gitlab-labkit-0.36.1 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.36.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.35.1 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.35.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.34.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.33.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.32.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.31.1 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.31.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.30.1 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.30.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.29.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.28.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.27.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.26.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.25.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.24.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.23.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.22.0 lib/labkit/tracing/grpc/server_interceptor.rb
gitlab-labkit-0.21.3 lib/labkit/tracing/grpc/server_interceptor.rb