Sha256: 3c2f2410855fdec0ea32ff431191798f4644c93fb70b61a063cac4653c83c25e

Contents?: true

Size: 1.36 KB

Versions: 28

Compression:

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

module Labkit
  module Correlation
    module GRPC
      # ClientInterceptor is used to inject the correlation_id into the metadata
      # or a GRPC call for onward propagation to the server
      class ClientInterceptor < ::GRPC::ClientInterceptor
        include Labkit::Correlation::GRPC::GRPCCommon
        include Singleton

        def request_response(request:, call:, method:, metadata:)
          inject_correlation_id_into_metadata(metadata)

          yield
        end

        def client_streamer(requests:, call:, method:, metadata:)
          inject_correlation_id_into_metadata(metadata)

          yield
        end

        def server_streamer(request:, call:, method:, metadata:)
          inject_correlation_id_into_metadata(metadata)

          yield
        end

        def bidi_streamer(requests:, call:, method:, metadata:)
          inject_correlation_id_into_metadata(metadata)

          yield
        end

        private

        def inject_correlation_id_into_metadata(metadata, &block)
          metadata[CORRELATION_METADATA_KEY] = Labkit::Correlation::CorrelationId.current_id if Labkit::Correlation::CorrelationId.current_id
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

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