class Labkit::Logging::GRPC::ServerInterceptor
Constants
- CODE_STRINGS
Public Class Methods
new(log_file, default_tags)
click to toggle source
Calls superclass method
# File lib/labkit/logging/grpc/server_interceptor.rb, line 34 def initialize(log_file, default_tags) @log_file = log_file @log_file.sync = true @default_tags = default_tags super() end
Public Instance Methods
bidi_streamer(requests: nil, call: nil, method: nil) { || ... }
click to toggle source
# File lib/labkit/logging/grpc/server_interceptor.rb, line 54 def bidi_streamer(requests: nil, call: nil, method: nil) log_request(method, call) { yield } end
client_streamer(call: nil, method: nil) { || ... }
click to toggle source
# File lib/labkit/logging/grpc/server_interceptor.rb, line 50 def client_streamer(call: nil, method: nil) log_request(method, call) { yield } end
request_response(request: nil, call: nil, method: nil) { || ... }
click to toggle source
# File lib/labkit/logging/grpc/server_interceptor.rb, line 42 def request_response(request: nil, call: nil, method: nil) log_request(method, call) { yield } end
server_streamer(request: nil, call: nil, method: nil) { || ... }
click to toggle source
# File lib/labkit/logging/grpc/server_interceptor.rb, line 46 def server_streamer(request: nil, call: nil, method: nil) log_request(method, call) { yield } end
Private Instance Methods
log_request(method, _call) { || ... }
click to toggle source
# File lib/labkit/logging/grpc/server_interceptor.rb, line 60 def log_request(method, _call) start = Time.now code = ::GRPC::Core::StatusCodes::OK yield rescue StandardError => ex code = ex.is_a?(::GRPC::BadStatus) ? ex.code : ::GRPC::Core::StatusCodes::UNKNOWN raise ensure service_name, method_name = rpc_split(method) message = @default_tags.merge( 'grpc.start_time': start.utc.rfc3339, 'grpc.time_ms': ((Time.now - start) * 1000.0).truncate(3), 'grpc.code': CODE_STRINGS.fetch(code, code.to_s), 'grpc.method': method_name, 'grpc.service': service_name, pid: Process.pid, correlation_id: Labkit::Correlation::CorrelationId.current_id.to_s, time: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ"), ) if ex message["exception"] = ex.message message["exception_backtrace"] = ex.backtrace[0..5] if ex.backtrace end @log_file.puts(JSON.dump(message)) end