Class: Gruf::Instrumentation::RequestContext
- Inherits:
-
Object
- Object
- Gruf::Instrumentation::RequestContext
- Defined in:
- lib/gruf/instrumentation/request_context.rb
Overview
Represents a request context for a given incoming gRPC request. This represents an injection layer that is used to pass to instrumentation strategies safely across thread boundaries.
Instance Attribute Summary collapse
-
#active_call ⇒ GRPC::ActiveCall
readonly
the call itself.
-
#call_signature ⇒ Symbol
readonly
Call_signature The gRPC method on the service that was called.
-
#execution_time ⇒ Time
readonly
Execution_time The execution time, in ms, of the request.
-
#request ⇒ Object
readonly
Request The protobuf request object.
-
#response ⇒ Object
readonly
Response The protobuf response object.
-
#service ⇒ Gruf::Service
readonly
Service The service to instrument.
Instance Method Summary collapse
-
#execution_time_rounded(precision: 2) ⇒ Float
Return the execution time rounded to a specified precision.
-
#initialize(service:, request:, response:, call_signature:, active_call:, execution_time: 0.00) ⇒ RequestContext
constructor
Initialize the request context given the request and response.
-
#response_class_name ⇒ String
Return the response class name.
-
#success? ⇒ Boolean
True if the response is successful.
Constructor Details
#initialize(service:, request:, response:, call_signature:, active_call:, execution_time: 0.00) ⇒ RequestContext
Initialize the request context given the request and response
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gruf/instrumentation/request_context.rb', line 41 def initialize( service:, request:, response:, call_signature:, active_call:, execution_time: 0.00 ) @service = service @request = request @response = response @call_signature = call_signature @active_call = active_call @execution_time = execution_time end |
Instance Attribute Details
#active_call ⇒ GRPC::ActiveCall (readonly)
the call itself
34 35 36 |
# File 'lib/gruf/instrumentation/request_context.rb', line 34 def active_call @active_call end |
#call_signature ⇒ Symbol (readonly)
Returns call_signature The gRPC method on the service that was called.
31 32 33 |
# File 'lib/gruf/instrumentation/request_context.rb', line 31 def call_signature @call_signature end |
#execution_time ⇒ Time (readonly)
Returns execution_time The execution time, in ms, of the request.
36 37 38 |
# File 'lib/gruf/instrumentation/request_context.rb', line 36 def execution_time @execution_time end |
#request ⇒ Object (readonly)
Returns request The protobuf request object.
27 28 29 |
# File 'lib/gruf/instrumentation/request_context.rb', line 27 def request @request end |
#response ⇒ Object (readonly)
Returns response The protobuf response object.
29 30 31 |
# File 'lib/gruf/instrumentation/request_context.rb', line 29 def response @response end |
#service ⇒ Gruf::Service (readonly)
Returns service The service to instrument.
25 26 27 |
# File 'lib/gruf/instrumentation/request_context.rb', line 25 def service @service end |
Instance Method Details
#execution_time_rounded(precision: 2) ⇒ Float
Return the execution time rounded to a specified precision
77 78 79 |
# File 'lib/gruf/instrumentation/request_context.rb', line 77 def execution_time_rounded(precision: 2) execution_time.to_f.round(precision) end |
#response_class_name ⇒ String
Return the response class name
67 68 69 |
# File 'lib/gruf/instrumentation/request_context.rb', line 67 def response_class_name response.class.name end |
#success? ⇒ Boolean
Returns True if the response is successful.
60 61 62 |
# File 'lib/gruf/instrumentation/request_context.rb', line 60 def success? !response.is_a?(GRPC::BadStatus) end |