Class: Gruf::Instrumentation::RequestLogging::Hook
- Defined in:
- lib/gruf/instrumentation/request_logging/hook.rb
Overview
Handles Rails-style request logging for gruf services.
This is added by default to gruf servers; if you have ‘Gruf.use_default_hooks = false`, you can add it back manually by doing:
Gruf::Instrumentation::Registry.add(:request_logging, Gruf::Instrumentation::RequestLogging::Hook)
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#call(rc) ⇒ String
Log the request, sending it to the appropriate formatter.
Methods inherited from Base
#initialize, #method_key, #outer_around, #service_key, #setup, #success?
Methods included from Loggable
Constructor Details
This class inherits a constructor from Gruf::Instrumentation::Base
Instance Method Details
#call(rc) ⇒ String
Log the request, sending it to the appropriate formatter
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gruf/instrumentation/request_logging/hook.rb', line 46 def call(rc) if rc.success? type = :info status_name = 'GRPC::Ok' else type = :error status_name = rc.response_class_name end payload = {} payload[:params] = sanitize(rc.request.to_h) if .fetch(:log_parameters, false) payload[:message] = (rc) payload[:service] = service_key payload[:method] = rc.call_signature payload[:action] = rc.call_signature payload[:grpc_status] = status_name payload[:duration] = rc.execution_time_rounded payload[:status] = status(rc.response, rc.success?) payload[:thread_id] = Thread.current.object_id payload[:time] = Time.now.to_s payload[:host] = Socket.gethostname ::Gruf.logger.send(type, formatter.format(payload)) end |