Sha256: ad01e5c6670f4bbbe105141c517470e1f3cc66694fb77aaa697c3592fca11499

Contents?: true

Size: 1.51 KB

Versions: 22

Compression:

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

# rubocop:enable Lint/UnusedMethodArgument

Version data entries

22 entries across 22 versions & 1 rubygems

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