Class: ZeroSilentFailures::Monitor

Inherits:
Logging::Monitor show all
Defined in:
lib/zero_silent_failures/monitor.rb

Overview

global monitoring functions for ZSF - statsd and logging

See Also:

Instance Attribute Summary

Attributes inherited from Logging::Monitor

#service

Instance Method Summary collapse

Methods inherited from Logging::Monitor

#initialize, #parse_caller, #track_request

Constructor Details

This class inherits a constructor from Logging::Monitor

Instance Method Details

#log_silent_failure(additional_context, user_account_uuid = nil, call_location: nil) ⇒ Object

record metrics and log for a silent failure

Parameters:

  • additional_context (Hash)

    information to accompany the log to aid in debugging

  • user_account_uuid (UUID) (defaults to: nil)
  • call_location (Logging::CallLocation | Thread::Backtrace::Location) (defaults to: nil)

    location to be logged as failure point



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/zero_silent_failures/monitor.rb', line 15

def log_silent_failure(additional_context,  = nil, call_location: nil)
  function, file, line = parse_caller(call_location || caller_locations.first)

  metric = 'silent_failure'
  message = 'Silent failure!'
  payload = {
    statsd: metric,
    service:,
    function:,
    file:,
    line:,
    user_account_uuid:,
    additional_context:
  }

  StatsD.increment(metric, tags: ["service:#{service}", "function:#{function}"])
  Rails.logger.error(message, payload)
end

#log_silent_failure_avoided(additional_context, user_account_uuid = nil, call_location: nil, email_confirmed: false) ⇒ Object

record metrics and log for a silent failure, avoided - an email was sent

Parameters:

  • additional_context (Hash)

    information to accompany the log to aid in debugging

  • user_account_uuid (UUID) (defaults to: nil)
  • call_location (Logging::CallLocation | Thread::Backtrace::Location) (defaults to: nil)

    location to be logged as failure point

  • email_confirmed (Boolean) (defaults to: false)

    whether the email was successfully delivered



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/zero_silent_failures/monitor.rb', line 40

def log_silent_failure_avoided(additional_context,  = nil, call_location: nil,
                               email_confirmed: false)
  function, file, line = parse_caller(call_location || caller_locations.first)

  metric = 'silent_failure_avoided'
  message = 'Silent failure avoided'

  unless email_confirmed
    metric = "#{metric}_no_confirmation"
    message = "#{message} (no confirmation)"
  end

  payload = {
    statsd: metric,
    service:,
    function:,
    file:,
    line:,
    user_account_uuid:,
    additional_context:
  }

  StatsD.increment(metric, tags: ["service:#{service}", "function:#{function}"])
  Rails.logger.error(message, payload)
end