Class: LogStruct::MultiErrorReporter

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/log_struct/multi_error_reporter.rb

Overview

MultiErrorReporter provides a unified interface for reporting errors to various services. You can also override this with your own error reporter by setting LogStruct#.config.error_reporting_handler NOTE: This is used for cases where an error should be reported but the operation should be allowed to continue (e.g. scrubbing log data.)

Class Method Summary collapse

Class Method Details

.detect_reporterErrorReporter

Auto-detect which error reporting service to use

Returns:



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/log_struct/multi_error_reporter.rb', line 54

def detect_reporter
  if defined?(::Sentry)
    ErrorReporter::Sentry
  elsif defined?(::Bugsnag)
    ErrorReporter::Bugsnag
  elsif defined?(::Rollbar)
    ErrorReporter::Rollbar
  elsif defined?(::Honeybadger)
    ErrorReporter::Honeybadger
  else
    ErrorReporter::RailsLogger
  end
end

.report_error(error, context = {}) ⇒ void

This method returns an undefined value.

Report an error to the configured error reporting service

Parameters:

  • error (StandardError)
  • context (Hash{T.untyped => T.untyped}) (defaults to: {})


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/log_struct/multi_error_reporter.rb', line 70

def report_error(error, context = {})
  # Call the appropriate reporter method based on what's available
  case reporter
  when ErrorReporter::Sentry
    report_to_sentry(error, context)
  when ErrorReporter::Bugsnag
    report_to_bugsnag(error, context)
  when ErrorReporter::Rollbar
    report_to_rollbar(error, context)
  when ErrorReporter::Honeybadger
    report_to_honeybadger(error, context)
  else
    fallback_logging(error, context)
  end
end

.reporterErrorReporter

Returns:



28
29
30
# File 'lib/log_struct/multi_error_reporter.rb', line 28

def reporter
  @reporter ||= detect_reporter
end

.reporter=(reporter_type) ⇒ ErrorReporter

Set the reporter to use (user-friendly API that accepts symbols)

Parameters:

Returns:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/log_struct/multi_error_reporter.rb', line 34

def reporter=(reporter_type)
  @reporter = case reporter_type
  when ErrorReporter
    reporter_type
  when Symbol
    case reporter_type
    when :sentry then ErrorReporter::Sentry
    when :bugsnag then ErrorReporter::Bugsnag
    when :rollbar then ErrorReporter::Rollbar
    when :honeybadger then ErrorReporter::Honeybadger
    when :rails_logger then ErrorReporter::RailsLogger
    else
      valid_types = ErrorReporter.values.map { |v| ":#{v.serialize}" }.join(", ")
      raise ArgumentError, "Unknown reporter type: #{reporter_type}. Valid types are: #{valid_types}"
    end
  end
end