Sha256: c283a492d72e80afc8c006b9ef18a169ef120732f362b7cef1d147379be8ee8a

Contents?: true

Size: 1.55 KB

Versions: 29

Compression:

Stored size: 1.55 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.
# rubocop:disable Lint/UnusedMethodArgument
require "opentracing"
require "grpc"

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

# rubocop:enable Lint/UnusedMethodArgument

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
gitlab-labkit-0.16.2 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.16.1 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.16.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.15.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.14.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.13.5 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.13.4 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.13.3 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.13.2 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.13.1 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.13.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.12.2 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.12.1 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.12.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.11.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.10.1 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.10.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.9.1 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.9.0 lib/labkit/tracing/grpc/client_interceptor.rb
gitlab-labkit-0.8.0 lib/labkit/tracing/grpc/client_interceptor.rb