Class: THTP::Server::Instrumentation::Logging

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/thtp/server/instrumentation.rb

Overview

A THTP::Server subscriber for RPC logging and exception recording

Instance Method Summary collapse

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

Parameters:

  • request (Rack::Request)

    The inbound HTTP request

  • error (Exception)

    The to-be-serialized exception

  • time (Integer)

    Milliseconds of execution wall time



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

Parameters:

  • request (Rack::Request)

    The inbound HTTP request

  • rpc (Symbol)

    The name of the RPC

  • args (Thrift::Struct?)

    The deserialized thrift args

  • error (THTP::ServerError)

    The to-be-serialized exception

  • time (Integer)

    Milliseconds of execution wall time



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

Parameters:

  • request (Rack::Request)

    The inbound HTTP request

  • rpc (Symbol)

    The name of the RPC

  • args (Thrift::Struct)

    The deserialized thrift args

  • exception (Thrift::Struct)

    The to-be-serialized thrift exception

  • time (Integer)

    Milliseconds of execution wall time



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

Parameters:

  • request (Rack::Request)

    The inbound HTTP request

  • rpc (Symbol)

    The name of the RPC

  • args (Thrift::Struct)

    The deserialized thrift args

  • result (Thrift::Struct)

    The to-be-serialized thrift response

  • time (Integer)

    Milliseconds of execution wall time



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