Class: RailsErrorDashboard::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/rails_error_dashboard/configuration.rb', line 137

def initialize
  # Default values - Authentication is ALWAYS required
  @dashboard_username = ENV.fetch("ERROR_DASHBOARD_USER", "gandalf")
  @dashboard_password = ENV.fetch("ERROR_DASHBOARD_PASSWORD", "youshallnotpass")
  @authenticate_with = nil

  @user_model = nil  # Auto-detect if not set

  # Multi-app support defaults
  @application_name = ENV["APPLICATION_NAME"]  # Auto-detected if not set
  @database = nil  # Use primary database by default

  # Notification settings (disabled by default - enable during installation or in initializer)
  @slack_webhook_url = ENV["SLACK_WEBHOOK_URL"]
  @notification_email_recipients = ENV.fetch("ERROR_NOTIFICATION_EMAILS", "").split(",").map(&:strip)
  @notification_email_from = ENV.fetch("ERROR_NOTIFICATION_FROM", "errors@example.com")
  @dashboard_base_url = ENV["DASHBOARD_BASE_URL"]
  @enable_slack_notifications = false
  @enable_email_notifications = false

  # Discord notification settings
  @discord_webhook_url = ENV["DISCORD_WEBHOOK_URL"]
  @enable_discord_notifications = false

  # PagerDuty notification settings (critical errors only)
  @pagerduty_integration_key = ENV["PAGERDUTY_INTEGRATION_KEY"]
  @enable_pagerduty_notifications = false

  # Generic webhook settings (array of URLs)
  @webhook_urls = ENV.fetch("WEBHOOK_URLS", "").split(",").map(&:strip).reject(&:empty?)
  @enable_webhook_notifications = false

  @use_separate_database = ENV.fetch("USE_SEPARATE_ERROR_DB", "false") == "true"

  # Retention policy - days to keep errors before automatic deletion (default: 90)
  # Set to nil to keep errors forever (not recommended for production)
  # Schedule cleanup: RailsErrorDashboard::RetentionCleanupJob.perform_later
  @retention_days = 90

  @enable_middleware = true
  @enable_error_subscriber = true

  # Advanced configuration defaults
  @custom_severity_rules = {}
  @ignored_exceptions = []
  @custom_fingerprint = nil # Lambda: ->(exception, context) { "custom_key" }
  @sampling_rate = 1.0 # 100% by default
  @async_logging = false
  @async_adapter = :sidekiq # Battle-tested default
  @max_backtrace_lines = 100 # Matches industry standard (Rollbar, Airbrake)

  # Rate limiting defaults
  @enable_rate_limiting = false # OFF by default (opt-in)
  @rate_limit_per_minute = 100  # Requests per minute per IP for API endpoints

  # Enhanced metrics defaults
  @app_version = ENV["APP_VERSION"]
  @git_sha = ENV["GIT_SHA"]
  @total_users_for_impact = nil # Auto-detect if not set
  @git_repository_url = ENV["GIT_REPOSITORY_URL"]

  # Advanced error analysis features (all OFF by default - opt-in)
  @enable_similar_errors = false        # Fuzzy error matching
  @enable_co_occurring_errors = false   # Co-occurring error detection
  @enable_error_cascades = false        # Error cascade detection
  @enable_error_correlation = false     # Version/user/time correlation
  @enable_platform_comparison = false   # Platform health comparison
  @enable_occurrence_patterns = false   # Pattern detection

  # Baseline alert defaults
  @enable_baseline_alerts = false  # OFF by default (opt-in)
  @baseline_alert_threshold_std_devs = ENV.fetch("BASELINE_ALERT_THRESHOLD", "2.0").to_f
  @baseline_alert_severities = [ :critical, :high ] # Alert on critical and high severity anomalies
  @baseline_alert_cooldown_minutes = ENV.fetch("BASELINE_ALERT_COOLDOWN", "120").to_i

  # Source code integration defaults - OFF by default (opt-in)
  @enable_source_code_integration = false  # Master switch
  @source_code_context_lines = 5  # Show ±5 lines around target line
  @enable_git_blame = false  # Show git blame info
  @source_code_cache_ttl = 3600  # 1 hour cache
  @only_show_app_code_source = true  # Hide gem/vendor code for security
  @git_branch_strategy = :commit_sha  # Use error's git_sha (most accurate)

  # Sensitive data filtering defaults - ON by default (filters passwords, tokens, credit cards, etc.)
  @filter_sensitive_data = true
  @sensitive_data_patterns = []

  # Notification throttling defaults
  @notification_minimum_severity = :low  # Notify on all severities (current behavior)
  @notification_cooldown_minutes = 5     # 5 min cooldown per error_hash (0 = disabled)
  @notification_threshold_alerts = [ 10, 50, 100, 500, 1000 ] # Occurrence milestones

  # Breadcrumbs defaults - OFF by default (opt-in)
  @enable_breadcrumbs = false         # Master switch
  @breadcrumb_buffer_size = 40        # Max events per request (Sentry uses 100, we're conservative)
  @breadcrumb_categories = nil        # nil = all; or [:sql, :controller, :cache, :job, :mailer, :custom, :deprecation]

  # N+1 query detection defaults - ON by default (lightweight display-time analysis)
  @enable_n_plus_one_detection = true  # Analyze SQL breadcrumbs for repeated patterns
  @n_plus_one_threshold = 3            # Flag when same query shape appears 3+ times

  # System health snapshot defaults - OFF by default (opt-in)
  @enable_system_health = false  # Capture GC, memory, threads, connection pool at error time

  # Internal logging defaults - SILENT by default
  @enable_internal_logging = false  # Opt-in for debugging
  @log_level = :silent  # Silent by default, use :debug, :info, :warn, :error, or :silent

  @notification_callbacks = {
    error_logged: [],
    critical_error: [],
    error_resolved: []
  }
end

Instance Attribute Details

#app_versionObject

Enhanced metrics



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

def app_version
  @app_version
end

#application_nameObject

Multi-app support - Application name



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

def application_name
  @application_name
end

#async_adapterObject

:sidekiq, :solid_queue, or :async



67
68
69
# File 'lib/rails_error_dashboard/configuration.rb', line 67

def async_adapter
  @async_adapter
end

#async_loggingObject

Async logging configuration



66
67
68
# File 'lib/rails_error_dashboard/configuration.rb', line 66

def async_logging
  @async_logging
end

#authenticate_withObject

Returns the value of attribute authenticate_with.



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

def authenticate_with
  @authenticate_with
end

#baseline_alert_cooldown_minutesObject

Minutes between alerts for same error type (default: 120)



96
97
98
# File 'lib/rails_error_dashboard/configuration.rb', line 96

def baseline_alert_cooldown_minutes
  @baseline_alert_cooldown_minutes
end

#baseline_alert_severitiesObject

Array of severities to alert on (default: [:critical, :high])



95
96
97
# File 'lib/rails_error_dashboard/configuration.rb', line 95

def baseline_alert_severities
  @baseline_alert_severities
end

#baseline_alert_threshold_std_devsObject

Number of std devs to trigger alert (default: 2.0)



94
95
96
# File 'lib/rails_error_dashboard/configuration.rb', line 94

def baseline_alert_threshold_std_devs
  @baseline_alert_threshold_std_devs
end

Max breadcrumbs per request (default: 40)



120
121
122
# File 'lib/rails_error_dashboard/configuration.rb', line 120

def breadcrumb_buffer_size
  @breadcrumb_buffer_size
end

Which categories to capture (default: nil = all)



121
122
123
# File 'lib/rails_error_dashboard/configuration.rb', line 121

def breadcrumb_categories
  @breadcrumb_categories
end

#custom_fingerprintObject

Custom fingerprint lambda for error deduplication When set, overrides the default ErrorHashGenerator logic. Receives (exception, context) and must return a String. Example: ->(exception, context) { “#RailsErrorDashboard::Configuration.exceptionexception.classexception.class.name:#:controller_name” }



60
61
62
# File 'lib/rails_error_dashboard/configuration.rb', line 60

def custom_fingerprint
  @custom_fingerprint
end

#custom_severity_rulesObject

Advanced configuration options Custom severity classification rules (hash of error_type => severity)



51
52
53
# File 'lib/rails_error_dashboard/configuration.rb', line 51

def custom_severity_rules
  @custom_severity_rules
end

#dashboard_base_urlObject

Returns the value of attribute dashboard_base_url.



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

def dashboard_base_url
  @dashboard_base_url
end

#dashboard_passwordObject

Returns the value of attribute dashboard_password.



7
8
9
# File 'lib/rails_error_dashboard/configuration.rb', line 7

def dashboard_password
  @dashboard_password
end

#dashboard_usernameObject

Dashboard authentication (always required)



6
7
8
# File 'lib/rails_error_dashboard/configuration.rb', line 6

def dashboard_username
  @dashboard_username
end

#databaseObject

Database connection name for shared error dashboard DB



15
16
17
# File 'lib/rails_error_dashboard/configuration.rb', line 15

def database
  @database
end

#discord_webhook_urlObject

Discord notifications



26
27
28
# File 'lib/rails_error_dashboard/configuration.rb', line 26

def discord_webhook_url
  @discord_webhook_url
end

#enable_baseline_alertsObject

Baseline alert configuration



93
94
95
# File 'lib/rails_error_dashboard/configuration.rb', line 93

def enable_baseline_alerts
  @enable_baseline_alerts
end

#enable_breadcrumbsObject

Breadcrumbs (request activity trail)



119
120
121
# File 'lib/rails_error_dashboard/configuration.rb', line 119

def enable_breadcrumbs
  @enable_breadcrumbs
end

#enable_co_occurring_errorsObject

Detect errors happening together



86
87
88
# File 'lib/rails_error_dashboard/configuration.rb', line 86

def enable_co_occurring_errors
  @enable_co_occurring_errors
end

#enable_discord_notificationsObject

Returns the value of attribute enable_discord_notifications.



27
28
29
# File 'lib/rails_error_dashboard/configuration.rb', line 27

def enable_discord_notifications
  @enable_discord_notifications
end

#enable_email_notificationsObject

Returns the value of attribute enable_email_notifications.



23
24
25
# File 'lib/rails_error_dashboard/configuration.rb', line 23

def enable_email_notifications
  @enable_email_notifications
end

#enable_error_cascadesObject

Parent→child error relationships



87
88
89
# File 'lib/rails_error_dashboard/configuration.rb', line 87

def enable_error_cascades
  @enable_error_cascades
end

#enable_error_correlationObject

Version/user/time correlation



88
89
90
# File 'lib/rails_error_dashboard/configuration.rb', line 88

def enable_error_correlation
  @enable_error_correlation
end

#enable_error_subscriberObject

Enable/disable Rails.error subscriber



47
48
49
# File 'lib/rails_error_dashboard/configuration.rb', line 47

def enable_error_subscriber
  @enable_error_subscriber
end

#enable_git_blameObject

Show git blame (default: false)



101
102
103
# File 'lib/rails_error_dashboard/configuration.rb', line 101

def enable_git_blame
  @enable_git_blame
end

#enable_internal_loggingObject

Internal logging configuration



134
135
136
# File 'lib/rails_error_dashboard/configuration.rb', line 134

def enable_internal_logging
  @enable_internal_logging
end

#enable_middlewareObject

Enable/disable error catching middleware



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

def enable_middleware
  @enable_middleware
end

#enable_n_plus_one_detectionObject

N+1 query detection (display-time analysis of SQL breadcrumbs)



124
125
126
# File 'lib/rails_error_dashboard/configuration.rb', line 124

def enable_n_plus_one_detection
  @enable_n_plus_one_detection
end

#enable_occurrence_patternsObject

Cyclical/burst pattern detection



90
91
92
# File 'lib/rails_error_dashboard/configuration.rb', line 90

def enable_occurrence_patterns
  @enable_occurrence_patterns
end

#enable_pagerduty_notificationsObject

Returns the value of attribute enable_pagerduty_notifications.



31
32
33
# File 'lib/rails_error_dashboard/configuration.rb', line 31

def enable_pagerduty_notifications
  @enable_pagerduty_notifications
end

#enable_platform_comparisonObject

iOS vs Android analytics



89
90
91
# File 'lib/rails_error_dashboard/configuration.rb', line 89

def enable_platform_comparison
  @enable_platform_comparison
end

#enable_rate_limitingObject

Rate limiting configuration



73
74
75
# File 'lib/rails_error_dashboard/configuration.rb', line 73

def enable_rate_limiting
  @enable_rate_limiting
end

#enable_similar_errorsObject

Advanced error analysis features



85
86
87
# File 'lib/rails_error_dashboard/configuration.rb', line 85

def enable_similar_errors
  @enable_similar_errors
end

#enable_slack_notificationsObject

Returns the value of attribute enable_slack_notifications.



22
23
24
# File 'lib/rails_error_dashboard/configuration.rb', line 22

def enable_slack_notifications
  @enable_slack_notifications
end

#enable_source_code_integrationObject

Source code integration (show code in backtrace)



99
100
101
# File 'lib/rails_error_dashboard/configuration.rb', line 99

def enable_source_code_integration
  @enable_source_code_integration
end

#enable_system_healthObject

System health snapshot (GC, memory, threads, connection pool at error time)



128
129
130
# File 'lib/rails_error_dashboard/configuration.rb', line 128

def enable_system_health
  @enable_system_health
end

#enable_webhook_notificationsObject

Returns the value of attribute enable_webhook_notifications.



35
36
37
# File 'lib/rails_error_dashboard/configuration.rb', line 35

def enable_webhook_notifications
  @enable_webhook_notifications
end

#filter_sensitive_dataObject

Sensitive data filtering (on by default) Redacts passwords, tokens, credit cards, SSNs, etc. before storage. Uses built-in defaults + Rails’ filter_parameters + custom patterns. Set to false if you want raw data stored (you own your database).



110
111
112
# File 'lib/rails_error_dashboard/configuration.rb', line 110

def filter_sensitive_data
  @filter_sensitive_data
end

#git_branch_strategyObject

:commit_sha, :current_branch, :main (default: :commit_sha)



104
105
106
# File 'lib/rails_error_dashboard/configuration.rb', line 104

def git_branch_strategy
  @git_branch_strategy
end

#git_repository_urlObject

Git repository URL for linking commits (e.g., “github.com/user/repo”)



82
83
84
# File 'lib/rails_error_dashboard/configuration.rb', line 82

def git_repository_url
  @git_repository_url
end

#git_shaObject

Returns the value of attribute git_sha.



78
79
80
# File 'lib/rails_error_dashboard/configuration.rb', line 78

def git_sha
  @git_sha
end

#ignored_exceptionsObject

Exceptions to ignore (array of strings, regexes, or classes)



54
55
56
# File 'lib/rails_error_dashboard/configuration.rb', line 54

def ignored_exceptions
  @ignored_exceptions
end

#log_levelObject

Returns the value of attribute log_level.



135
136
137
# File 'lib/rails_error_dashboard/configuration.rb', line 135

def log_level
  @log_level
end

#max_backtrace_linesObject

Backtrace configuration



70
71
72
# File 'lib/rails_error_dashboard/configuration.rb', line 70

def max_backtrace_lines
  @max_backtrace_lines
end

#n_plus_one_thresholdObject

Min repetitions to flag (default: 3, min: 2)



125
126
127
# File 'lib/rails_error_dashboard/configuration.rb', line 125

def n_plus_one_threshold
  @n_plus_one_threshold
end

#notification_callbacksObject (readonly)

Notification callbacks (managed via helper methods, not set directly)



131
132
133
# File 'lib/rails_error_dashboard/configuration.rb', line 131

def notification_callbacks
  @notification_callbacks
end

#notification_cooldown_minutesObject

Per-error cooldown in minutes (default: 5, 0 = disabled)



115
116
117
# File 'lib/rails_error_dashboard/configuration.rb', line 115

def notification_cooldown_minutes
  @notification_cooldown_minutes
end

#notification_email_fromObject

Returns the value of attribute notification_email_from.



20
21
22
# File 'lib/rails_error_dashboard/configuration.rb', line 20

def notification_email_from
  @notification_email_from
end

#notification_email_recipientsObject

Returns the value of attribute notification_email_recipients.



19
20
21
# File 'lib/rails_error_dashboard/configuration.rb', line 19

def notification_email_recipients
  @notification_email_recipients
end

#notification_minimum_severityObject

Notification throttling (prevents alert fatigue)



114
115
116
# File 'lib/rails_error_dashboard/configuration.rb', line 114

def notification_minimum_severity
  @notification_minimum_severity
end

#notification_threshold_alertsObject

Occurrence milestones that trigger notification (default: [10, 50, 100, 500, 1000])



116
117
118
# File 'lib/rails_error_dashboard/configuration.rb', line 116

def notification_threshold_alerts
  @notification_threshold_alerts
end

#only_show_app_code_sourceObject

Hide gems/stdlib (default: true)



103
104
105
# File 'lib/rails_error_dashboard/configuration.rb', line 103

def only_show_app_code_source
  @only_show_app_code_source
end

#pagerduty_integration_keyObject

PagerDuty notifications (critical errors only)



30
31
32
# File 'lib/rails_error_dashboard/configuration.rb', line 30

def pagerduty_integration_key
  @pagerduty_integration_key
end

#rate_limit_per_minuteObject

Returns the value of attribute rate_limit_per_minute.



74
75
76
# File 'lib/rails_error_dashboard/configuration.rb', line 74

def rate_limit_per_minute
  @rate_limit_per_minute
end

#retention_daysObject

Retention policy (days to keep errors)



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

def retention_days
  @retention_days
end

#sampling_rateObject

Sampling rate for non-critical errors (0.0 to 1.0, default 1.0 = 100%)



63
64
65
# File 'lib/rails_error_dashboard/configuration.rb', line 63

def sampling_rate
  @sampling_rate
end

#sensitive_data_patternsObject

Additional patterns beyond Rails’ filter_parameters



111
112
113
# File 'lib/rails_error_dashboard/configuration.rb', line 111

def sensitive_data_patterns
  @sensitive_data_patterns
end

#slack_webhook_urlObject

Notifications



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

def slack_webhook_url
  @slack_webhook_url
end

#source_code_cache_ttlObject

Cache TTL in seconds (default: 3600)



102
103
104
# File 'lib/rails_error_dashboard/configuration.rb', line 102

def source_code_cache_ttl
  @source_code_cache_ttl
end

#source_code_context_linesObject

Lines before/after (default: 5)



100
101
102
# File 'lib/rails_error_dashboard/configuration.rb', line 100

def source_code_context_lines
  @source_code_context_lines
end

#total_users_for_impactObject

For user impact % calculation



79
80
81
# File 'lib/rails_error_dashboard/configuration.rb', line 79

def total_users_for_impact
  @total_users_for_impact
end

#use_separate_databaseObject

Separate database configuration



38
39
40
# File 'lib/rails_error_dashboard/configuration.rb', line 38

def use_separate_database
  @use_separate_database
end

#user_modelObject

User model (for associations)



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

def user_model
  @user_model
end

#webhook_urlsObject

Generic webhook notifications



34
35
36
# File 'lib/rails_error_dashboard/configuration.rb', line 34

def webhook_urls
  @webhook_urls
end

Instance Method Details

#clear_total_users_cache!Object

Clear the total users cache



431
432
433
# File 'lib/rails_error_dashboard/configuration.rb', line 431

def clear_total_users_cache!
  @total_users_cache = {}
end

#effective_total_usersInteger?

Get the effective total users count (auto-detected if not configured) Caches the result for 5 minutes to avoid repeated queries

Returns:

  • (Integer, nil)

    Total users count



410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/rails_error_dashboard/configuration.rb', line 410

def effective_total_users
  return @total_users_for_impact if @total_users_for_impact.present?

  # Cache auto-detected value for 5 minutes
  @total_users_cache ||= {}
  cache_key = :auto_detected_count
  cached_at = @total_users_cache[:cached_at]

  if cached_at && (Time.current - cached_at) < 300 # 5 minutes
    return @total_users_cache[cache_key]
  end

  count = RailsErrorDashboard::Helpers::UserModelDetector.detect_total_users

  @total_users_cache[cache_key] = count
  @total_users_cache[:cached_at] = Time.current

  count
end

#effective_user_modelString?

Get the effective user model (auto-detected if not configured)

Returns:

  • (String, nil)

    User model class name



400
401
402
403
404
# File 'lib/rails_error_dashboard/configuration.rb', line 400

def effective_user_model
  return @user_model if @user_model.present?

  RailsErrorDashboard::Helpers::UserModelDetector.detect_user_model
end

#reset!Object

Reset configuration to defaults



253
254
255
# File 'lib/rails_error_dashboard/configuration.rb', line 253

def reset!
  initialize
end

#validate!true

Validate configuration values Raises ConfigurationError if any validation fails

Returns:

  • (true)

    if configuration is valid

Raises:



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/rails_error_dashboard/configuration.rb', line 262

def validate!
  errors = []

  # Validate sampling_rate (must be between 0.0 and 1.0)
  if sampling_rate && (sampling_rate < 0.0 || sampling_rate > 1.0)
    errors << "sampling_rate must be between 0.0 and 1.0 (got: #{sampling_rate})"
  end

  # Validate retention_days (must be positive)
  if retention_days && retention_days < 1
    errors << "retention_days must be at least 1 day (got: #{retention_days})"
  end

  # Validate max_backtrace_lines (must be positive)
  if max_backtrace_lines && max_backtrace_lines < 1
    errors << "max_backtrace_lines must be at least 1 (got: #{max_backtrace_lines})"
  end

  # Validate rate_limit_per_minute (must be positive if rate limiting enabled)
  if enable_rate_limiting && rate_limit_per_minute && rate_limit_per_minute < 1
    errors << "rate_limit_per_minute must be at least 1 (got: #{rate_limit_per_minute})"
  end

  # Validate baseline alert threshold (must be positive)
  if enable_baseline_alerts && baseline_alert_threshold_std_devs && baseline_alert_threshold_std_devs <= 0
    errors << "baseline_alert_threshold_std_devs must be positive (got: #{baseline_alert_threshold_std_devs})"
  end

  # Validate baseline alert cooldown (must be positive)
  if enable_baseline_alerts && baseline_alert_cooldown_minutes && baseline_alert_cooldown_minutes < 1
    errors << "baseline_alert_cooldown_minutes must be at least 1 (got: #{baseline_alert_cooldown_minutes})"
  end

  # Validate baseline alert severities (must be valid symbols)
  if enable_baseline_alerts && baseline_alert_severities
    valid_severities = %i[critical high medium low]
    invalid_severities = baseline_alert_severities - valid_severities
    if invalid_severities.any?
      errors << "baseline_alert_severities contains invalid values: #{invalid_severities.inspect}. " \
                "Valid options: #{valid_severities.inspect}"
    end
  end

  # Validate async_adapter (must be valid adapter)
  if async_logging && async_adapter
    valid_adapters = %i[sidekiq solid_queue async]
    unless valid_adapters.include?(async_adapter)
      errors << "async_adapter must be one of #{valid_adapters.inspect} (got: #{async_adapter.inspect})"
    end
  end

  # Validate custom_fingerprint (must respond to .call if set)
  if custom_fingerprint && !custom_fingerprint.respond_to?(:call)
    errors << "custom_fingerprint must respond to .call (lambda, proc, or object with .call method)"
  end

  # Validate authenticate_with (must respond to .call if set)
  if authenticate_with && !authenticate_with.respond_to?(:call)
    errors << "authenticate_with must respond to .call (lambda, proc, or object with .call method)"
  end

  # Validate breadcrumb_buffer_size (must be positive if breadcrumbs enabled)
  if enable_breadcrumbs && breadcrumb_buffer_size && breadcrumb_buffer_size < 1
    errors << "breadcrumb_buffer_size must be at least 1 (got: #{breadcrumb_buffer_size})"
  end

  # Validate n_plus_one_threshold (must be at least 2 if detection enabled)
  if enable_n_plus_one_detection && n_plus_one_threshold && n_plus_one_threshold < 2
    errors << "n_plus_one_threshold must be at least 2 (got: #{n_plus_one_threshold})"
  end

  # Validate notification dependencies
  if enable_slack_notifications && (slack_webhook_url.nil? || slack_webhook_url.strip.empty?)
    errors << "slack_webhook_url is required when enable_slack_notifications is true"
  end

  if enable_email_notifications && notification_email_recipients.empty?
    errors << "notification_email_recipients is required when enable_email_notifications is true"
  end

  if enable_discord_notifications && (discord_webhook_url.nil? || discord_webhook_url.strip.empty?)
    errors << "discord_webhook_url is required when enable_discord_notifications is true"
  end

  if enable_pagerduty_notifications && (pagerduty_integration_key.nil? || pagerduty_integration_key.strip.empty?)
    errors << "pagerduty_integration_key is required when enable_pagerduty_notifications is true"
  end

  if enable_webhook_notifications && webhook_urls.empty?
    errors << "webhook_urls is required when enable_webhook_notifications is true"
  end

  # Validate separate database configuration
  if use_separate_database && (database.nil? || database.to_s.strip.empty?)
    errors << "database configuration is required when use_separate_database is true"
  end

  # Validate log level (must be valid symbol)
  if log_level
    valid_log_levels = %i[debug info warn error fatal silent]
    unless valid_log_levels.include?(log_level)
      errors << "log_level must be one of #{valid_log_levels.inspect} (got: #{log_level.inspect})"
    end
  end

  # Validate total_users_for_impact (must be positive if set)
  if total_users_for_impact && total_users_for_impact < 1
    errors << "total_users_for_impact must be at least 1 (got: #{total_users_for_impact})"
  end

  # Validate notification_minimum_severity (must be valid symbol)
  if notification_minimum_severity
    valid_notification_severities = %i[critical high medium low]
    unless valid_notification_severities.include?(notification_minimum_severity)
      errors << "notification_minimum_severity must be one of #{valid_notification_severities.inspect} " \
                "(got: #{notification_minimum_severity.inspect})"
    end
  end

  # Validate notification_cooldown_minutes (must be non-negative if set)
  if notification_cooldown_minutes && notification_cooldown_minutes < 0
    errors << "notification_cooldown_minutes must be 0 or greater (got: #{notification_cooldown_minutes})"
  end

  # Validate notification_threshold_alerts (must be array of positive integers if set)
  if notification_threshold_alerts && !notification_threshold_alerts.is_a?(Array)
    errors << "notification_threshold_alerts must be an Array (got: #{notification_threshold_alerts.class})"
  end

  # Raise exception if any errors found
  raise ConfigurationError, errors if errors.any?

  true
end