Class: Logging::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/logging/monitor.rb

Overview

generic monitoring class

Direct Known Subclasses

ZeroSilentFailures::Monitor

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#serviceObject (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`

Parameters:

  • call_location (CallLocation | Thread::Backtrace::Location)

    location to be logged as failure point

See Also:



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

Parameters:

  • error_level (String)
  • message (String)
  • metric (String)
  • call_location (Logging::CallLocation | Thread::Backtrace::Location) (defaults to: nil)

    location to be logged as failure point

  • context (Hash)

    additional parameters to pass to log



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, message, 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, message.to_s, payload)
  else
    Rails.logger.error("Invalid log error_level: #{error_level}")
  end
end