Class: KubeMQ::Interceptors::MetricsInterceptor Private
- Inherits:
-
GRPC::ClientInterceptor
- Object
- GRPC::ClientInterceptor
- KubeMQ::Interceptors::MetricsInterceptor
- 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
-
.otel_available? ⇒ Boolean
private
Returns whether the OpenTelemetry API is loaded and configured.
Instance Method Summary collapse
-
#bidi_streamer(requests:, call:, method:, metadata:, &block) ⇒ Enumerator
private
Bidirectional response stream.
-
#client_streamer(requests:, call:, method:, metadata:, &block) ⇒ Object
private
The RPC response.
-
#initialize ⇒ MetricsInterceptor
constructor
private
A new instance of MetricsInterceptor.
-
#request_response(request:, call:, method:, metadata:, &block) ⇒ Object
private
The RPC response.
-
#server_streamer(request:, call:, method:, metadata:, &block) ⇒ Enumerator
private
Server response stream.
Constructor Details
#initialize ⇒ MetricsInterceptor
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.
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.
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.
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.
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.
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 |