Class: ErrorRadar::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/error_radar/configuration.rb

Overview

Holds every host-app-specific decision so the engine stays decoupled. Configure from an initializer (see the install generator’s template).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/error_radar/configuration.rb', line 46

def initialize
  @enabled            = true
  @backtrace_lines    = 30
  @max_message_length = 4_000
  @ignored_exceptions = %w[
    ActionController::RoutingError
    ActiveRecord::RecordNotFound
    ActionController::ParameterMissing
    ActionController::UnknownFormat
    ActionController::BadRequest
    ActionController::InvalidAuthenticityToken
    ActionDispatch::Http::Parameters::ParseError
  ]
  @sensitive_params   = %w[password password_confirmation token access_token authorization secret]
  @install_middleware = true
  @install_sidekiq    = true
  @install_rails_admin = true
  @categorizers       = []
  @detail_extractors  = []
  @expected_servers   = []
  @authenticate       = nil
  @current_user       = nil
end

Instance Attribute Details

#authenticateObject

Dashboard auth: ‘->(controller) { … }` run as a before_action. Raise / redirect inside it to deny access. nil => no auth (NOT recommended in prod).



41
42
43
# File 'lib/error_radar/configuration.rb', line 41

def authenticate
  @authenticate
end

#backtrace_linesObject

How many backtrace lines to persist.



11
12
13
# File 'lib/error_radar/configuration.rb', line 11

def backtrace_lines
  @backtrace_lines
end

#categorizersObject

Custom classification rules. Each is a callable ‘->(exception) { :category | nil }`. The first rule that returns a non-nil category wins; built-in rules run after.



28
29
30
# File 'lib/error_radar/configuration.rb', line 28

def categorizers
  @categorizers
end

#current_userObject

‘->(controller) { “who@acted” }` — stamped onto resolved errors.



44
45
46
# File 'lib/error_radar/configuration.rb', line 44

def current_user
  @current_user
end

#detail_extractorsObject

Extract extra structured columns from custom exception types. Each is a callable ‘->(exception) { { http_status:, request_url:, api_code:, api_subcode: } | nil }`.



32
33
34
# File 'lib/error_radar/configuration.rb', line 32

def detail_extractors
  @detail_extractors
end

#enabledObject

Master switch — set false (e.g. in test env) to make capture a no-op.



8
9
10
# File 'lib/error_radar/configuration.rb', line 8

def enabled
  @enabled
end

#expected_serversObject

Optional Sidekiq process expectations for the dashboard’s server panel. Each entry: { key:, name:, tag:, host:, queue_hint: }. Empty => the panel simply lists whatever live processes exist.



37
38
39
# File 'lib/error_radar/configuration.rb', line 37

def expected_servers
  @expected_servers
end

#ignored_exceptionsObject

Exception class names the Rack middleware must NOT log (expected client outcomes: routing errors, 404s, bad requests, …).



18
19
20
# File 'lib/error_radar/configuration.rb', line 18

def ignored_exceptions
  @ignored_exceptions
end

#install_middlewareObject

Integration toggles.



24
25
26
# File 'lib/error_radar/configuration.rb', line 24

def install_middleware
  @install_middleware
end

#install_rails_adminObject

Integration toggles.



24
25
26
# File 'lib/error_radar/configuration.rb', line 24

def install_rails_admin
  @install_rails_admin
end

#install_sidekiqObject

Integration toggles.



24
25
26
# File 'lib/error_radar/configuration.rb', line 24

def install_sidekiq
  @install_sidekiq
end

#max_message_lengthObject

Truncate stored messages to this many chars.



14
15
16
# File 'lib/error_radar/configuration.rb', line 14

def max_message_length
  @max_message_length
end

#sensitive_paramsObject

Request param keys to scrub before persisting them in ‘context`.



21
22
23
# File 'lib/error_radar/configuration.rb', line 21

def sensitive_params
  @sensitive_params
end

Instance Method Details

#categorize(&block) ⇒ Object

Convenience DSL inside ‘configure`:

c.categorize { |e| :external_api if e.is_a?(MyApi::Error) }


72
73
74
# File 'lib/error_radar/configuration.rb', line 72

def categorize(&block)
  @categorizers << block
end

#extract_details(&block) ⇒ Object

c.extract_details { |e| { http_status: e.status } if e.is_a?(MyApi::Error) }



77
78
79
# File 'lib/error_radar/configuration.rb', line 77

def extract_details(&block)
  @detail_extractors << block
end