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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gruf/instrumentation/request_context.rb', line 25 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
18 19 20 |
# File 'lib/gruf/instrumentation/request_context.rb', line 18 def active_call @active_call end |
#call_signature ⇒ Symbol (readonly)
Returns call_signature The gRPC method on the service that was called.
15 16 17 |
# File 'lib/gruf/instrumentation/request_context.rb', line 15 def call_signature @call_signature end |
#execution_time ⇒ Time (readonly)
Returns execution_time The execution time, in ms, of the request.
20 21 22 |
# File 'lib/gruf/instrumentation/request_context.rb', line 20 def execution_time @execution_time end |
#request ⇒ Object (readonly)
Returns request The protobuf request object.
11 12 13 |
# File 'lib/gruf/instrumentation/request_context.rb', line 11 def request @request end |
#response ⇒ Object (readonly)
Returns response The protobuf response object.
13 14 15 |
# File 'lib/gruf/instrumentation/request_context.rb', line 13 def response @response end |
#service ⇒ Gruf::Service (readonly)
Returns service The service to instrument.
9 10 11 |
# File 'lib/gruf/instrumentation/request_context.rb', line 9 def service @service end |
Instance Method Details
#execution_time_rounded(precision: 2) ⇒ Float
Return the execution time rounded to a specified precision
61 62 63 |
# File 'lib/gruf/instrumentation/request_context.rb', line 61 def execution_time_rounded(precision: 2) execution_time.to_f.round(precision) end |
#response_class_name ⇒ String
Return the response class name
51 52 53 |
# File 'lib/gruf/instrumentation/request_context.rb', line 51 def response_class_name response.class.name end |
#success? ⇒ Boolean
Returns True if the response is successful.
44 45 46 |
# File 'lib/gruf/instrumentation/request_context.rb', line 44 def success? !response.is_a?(GRPC::BadStatus) end |