Sha256: 53c377569961fa9ae83346468fd187ec950a72877b32d379ebabd68b3244e371

Contents?: true

Size: 1.42 KB

Versions: 28

Compression:

Stored size: 1.42 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"

module Labkit
  module Correlation
    module GRPC
      # ServerInterceptor is a server-side GRPC interceptor
      # for injecting GRPC calls with a correlation-id passed from
      # a GRPC client to the GRPC Ruby Service
      class ServerInterceptor < ::GRPC::ServerInterceptor
        include Labkit::Correlation::GRPC::GRPCCommon

        def request_response(request: nil, call: nil, method: nil)
          wrap_with_correlation_id(call) do
            yield
          end
        end

        def client_streamer(call: nil, method: nil)
          wrap_with_correlation_id(call) do
            yield
          end
        end

        def server_streamer(request: nil, call: nil, method: nil)
          wrap_with_correlation_id(call) do
            yield
          end
        end

        def bidi_streamer(requests: nil, call: nil, method: nil)
          wrap_with_correlation_id(call) do
            yield
          end
        end

        private

        def wrap_with_correlation_id(call, &block)
          correlation_id = call.metadata[CORRELATION_METADATA_KEY]
          correlation_id ||= Labkit::Correlation::CorrelationId.current_or_new_id

          Labkit::Correlation::CorrelationId.use_id(correlation_id, &block)
        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/server_interceptor.rb
gitlab-labkit-0.36.1 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.36.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.35.1 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.35.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.34.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.33.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.32.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.31.1 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.31.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.30.1 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.30.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.29.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.28.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.27.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.26.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.25.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.24.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.23.0 lib/labkit/correlation/grpc/server_interceptor.rb
gitlab-labkit-0.22.0 lib/labkit/correlation/grpc/server_interceptor.rb