Class: THTP::Server::Instrumentation::Logging
- Inherits:
-
Object
- Object
- THTP::Server::Instrumentation::Logging
- Includes:
- Utils
- Defined in:
- lib/thtp/server/instrumentation.rb
Overview
A THTP::Server subscriber for RPC logging and exception recording
Instance Method Summary collapse
-
#initialize(logger, backtrace_lines: 10) ⇒ Logging
constructor
A new instance of Logging.
-
#internal_error(request:, error:, time:) ⇒ Object
An unknown error occurred.
-
#rpc_error(request:, rpc:, args:, error:, time:) ⇒ Object
Handler raised an unexpected error.
-
#rpc_exception(request:, rpc:, args:, exception:, time:) ⇒ Object
Handler raised an exception defined in the schema.
-
#rpc_success(request:, rpc:, args:, result:, time:) ⇒ Object
Everything went according to plan.
Methods included from Utils
#args_class, #canonical_name, #deserialize, #deserialize_buffer, #deserialize_stream, #elapsed_ms, #extract_rpcs, #get_time, #jsonify, #result_class, #serialize, #serialize_buffer, #serialize_stream
Constructor Details
#initialize(logger, backtrace_lines: 10) ⇒ Logging
Returns a new instance of Logging.
75 76 77 78 |
# File 'lib/thtp/server/instrumentation.rb', line 75 def initialize(logger, backtrace_lines: 10) @logger = logger @backtrace_lines = backtrace_lines end |
Instance Method Details
#internal_error(request:, error:, time:) ⇒ Object
An unknown error occurred
138 139 140 141 142 143 144 145 146 |
# File 'lib/thtp/server/instrumentation.rb', line 138 def internal_error(request:, error:, time:) @logger.error :server do { http: http_request_to_hash(request), internal_error: error_to_hash(error), elapsed_ms: time, } end end |
#rpc_error(request:, rpc:, args:, error:, time:) ⇒ Object
Handler raised an unexpected error
122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/thtp/server/instrumentation.rb', line 122 def rpc_error(request:, rpc:, args:, error:, time:) @logger.error :rpc do { rpc: rpc, http: http_request_to_hash(request), request: args_to_hash(args), error: error_to_hash(error), elapsed_ms: time, } end end |
#rpc_exception(request:, rpc:, args:, exception:, time:) ⇒ Object
Handler raised an exception defined in the schema
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/thtp/server/instrumentation.rb', line 104 def rpc_exception(request:, rpc:, args:, exception:, time:) @logger.info :rpc do { rpc: rpc, http: http_request_to_hash(request), request: args_to_hash(args), exception: result_to_hash(exception), elapsed_ms: time, } end end |
#rpc_success(request:, rpc:, args:, result:, time:) ⇒ Object
Everything went according to plan
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/thtp/server/instrumentation.rb', line 86 def rpc_success(request:, rpc:, args:, result:, time:) @logger.info :rpc do { rpc: rpc, http: http_request_to_hash(request), request: args_to_hash(args), result: result_to_hash(result), elapsed_ms: time, } end end |