Class: KubeMQ::Interceptors::MetricsInterceptor Private

Inherits:
GRPC::ClientInterceptor
  • Object
show all
Defined in:
lib/kubemq/interceptors/metrics_interceptor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

gRPC client interceptor that creates OpenTelemetry spans around each RPC.

When the OpenTelemetry SDK is loaded, wraps every call in a named span with messaging.system=kubemq. When OpenTelemetry is not available, passes through without overhead.

Unary and server-streaming RPCs use :client span kind; client-streaming and bidirectional RPCs use :producer span kind.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetricsInterceptor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MetricsInterceptor.



21
22
23
24
# File 'lib/kubemq/interceptors/metrics_interceptor.rb', line 21

def initialize
  super
  @otel_available = self.class.otel_available?
end

Class Method Details

.otel_available?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns whether the OpenTelemetry API is loaded and configured.

Returns:

  • (Boolean)

    true if OpenTelemetry.tracer_provider is available



29
30
31
# File 'lib/kubemq/interceptors/metrics_interceptor.rb', line 29

def self.otel_available?
  defined?(OpenTelemetry) && OpenTelemetry.respond_to?(:tracer_provider)
end

Instance Method Details

#bidi_streamer(requests:, call:, method:, metadata:, &block) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns bidirectional response stream.

Parameters:

  • requests (Enumerator)

    the outbound request stream

  • call (GRPC::ActiveCall)

    the active gRPC call

  • method (String)

    the RPC method path

  • metadata (Hash)

    request metadata

Returns:

  • (Enumerator)

    bidirectional response stream



77
78
79
80
81
82
83
# File 'lib/kubemq/interceptors/metrics_interceptor.rb', line 77

def bidi_streamer(requests:, call:, method:, metadata:, &block)
  return block.call(requests, call, method, ) unless @otel_available

  with_span(method, :producer) do
    block.call(requests, call, method, )
  end
end

#client_streamer(requests:, call:, method:, metadata:, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the RPC response.

Parameters:

  • requests (Enumerator)

    the outbound request stream

  • call (GRPC::ActiveCall)

    the active gRPC call

  • method (String)

    the RPC method path

  • metadata (Hash)

    request metadata

Returns:

  • (Object)

    the RPC response



64
65
66
67
68
69
70
# File 'lib/kubemq/interceptors/metrics_interceptor.rb', line 64

def client_streamer(requests:, call:, method:, metadata:, &block)
  return block.call(requests, call, method, ) unless @otel_available

  with_span(method, :producer) do
    block.call(requests, call, method, )
  end
end

#request_response(request:, call:, method:, metadata:, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the RPC response.

Parameters:

  • request (Object)

    the outbound protobuf message

  • call (GRPC::ActiveCall)

    the active gRPC call

  • method (String)

    the RPC method path

  • metadata (Hash)

    request metadata

Returns:

  • (Object)

    the RPC response



38
39
40
41
42
43
44
# File 'lib/kubemq/interceptors/metrics_interceptor.rb', line 38

def request_response(request:, call:, method:, metadata:, &block)
  return block.call(request, call, method, ) unless @otel_available

  with_span(method, :client) do
    block.call(request, call, method, )
  end
end

#server_streamer(request:, call:, method:, metadata:, &block) ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns server response stream.

Parameters:

  • request (Object)

    the outbound protobuf message

  • call (GRPC::ActiveCall)

    the active gRPC call

  • method (String)

    the RPC method path

  • metadata (Hash)

    request metadata

Returns:

  • (Enumerator)

    server response stream



51
52
53
54
55
56
57
# File 'lib/kubemq/interceptors/metrics_interceptor.rb', line 51

def server_streamer(request:, call:, method:, metadata:, &block)
  return block.call(request, call, method, ) unless @otel_available

  with_span(method, :client) do
    block.call(request, call, method, )
  end
end