Class: Logging::Monitor
- Inherits:
-
Object
- Object
- Logging::Monitor
- Defined in:
- lib/logging/monitor.rb
Overview
generic monitoring class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
private
Returns the value of attribute service.
Instance Method Summary collapse
-
#initialize(service) ⇒ Monitor
constructor
create a monitor.
-
#parse_caller(call_location) ⇒ Object
private
parse information from the ‘caller` defaults to the location calling `track_request`.
-
#track_request(error_level, message, metric, call_location: nil, **additional_context) ⇒ Object
monitor application.
Constructor Details
#initialize(service) ⇒ Monitor
create a monitor
7 8 9 |
# File 'lib/logging/monitor.rb', line 7 def initialize(service) @service = service end |
Instance Attribute Details
#service ⇒ Object (readonly, private)
Returns the value of attribute service.
42 43 44 |
# File 'lib/logging/monitor.rb', line 42 def service @service end |
Instance Method Details
#parse_caller(call_location) ⇒ Object (private)
parse information from the ‘caller` defaults to the location calling `track_request`
52 53 54 55 |
# File 'lib/logging/monitor.rb', line 52 def parse_caller(call_location) call_location ||= caller_locations.second [call_location.base_label, call_location.path, call_location.lineno] end |
#track_request(error_level, message, metric, call_location: nil, **additional_context) ⇒ Object
monitor application
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/logging/monitor.rb', line 19 def track_request(error_level, , metric, call_location: nil, **additional_context) function, file, line = parse_caller(call_location) StatsD.increment(metric, tags: additional_context[:tags]) if %w[debug info warn error fatal unknown].include?(error_level) payload = { statsd: metric, service:, user_account_uuid: additional_context[:user_account_uuid], function:, file:, line:, additional_context: } Rails.logger.public_send(error_level, .to_s, payload) else Rails.logger.error("Invalid log error_level: #{error_level}") end end |