Sha256: cd988b2cf63c0e7d9f385dd34245b4fac31c59324c4ba764da8b0267fcfad86d

Contents?: true

Size: 1.48 KB

Versions: 27

Compression:

Stored size: 1.48 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"
require "singleton"

module Labkit
  module Tracing
    module GRPC
      # GRPCClientInterceptor is a client-side GRPC interceptor
      # for instrumenting GRPC calls with distributed tracing
      class ClientInterceptor < ::GRPC::ClientInterceptor
        include Singleton

        def request_response(request:, call:, method:, metadata:)
          wrap_with_tracing(method, "unary", metadata) { yield }
        end

        def client_streamer(requests:, call:, method:, metadata:)
          wrap_with_tracing(method, "client_stream", metadata) { yield }
        end

        def server_streamer(request:, call:, method:, metadata:)
          wrap_with_tracing(method, "server_stream", metadata) { yield }
        end

        def bidi_streamer(requests:, call:, method:, metadata:)
          wrap_with_tracing(method, "bidi_stream", metadata) { yield }
        end

        private

        def wrap_with_tracing(method, grpc_type, metadata)
          tags = { "component" => "grpc", "span.kind" => "client", "grpc.method" => method, "grpc.type" => grpc_type }

          TracingUtils.with_tracing(operation_name: "grpc:#{method}", tags: tags) do |span|
            OpenTracing.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, metadata)

            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/client_interceptor.rb
gitlab-labkit-0.36.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.35.1 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.35.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.34.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.33.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.32.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.31.1 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.31.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.30.1 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.30.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.29.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.28.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.27.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.26.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.25.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.24.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.23.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.22.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.21.3 lib/labkit/tracing/grpc/client_interceptor.rb