Class: RailsErrorDashboard::ErrorOccurrence

Inherits:
ErrorLogsRecord
  • Object
show all
Defined in:
app/models/rails_error_dashboard/error_occurrence.rb

Overview

Tracks individual occurrences of errors for co-occurrence analysis

Each time an error is logged, we create an ErrorOccurrence record to track when it happened, who was affected, and what request caused it. This allows us to find errors that occur together in time windows.

Instance Method Summary collapse

Instance Method Details

#co_occurring_error_types(window_minutes: 5) ⇒ ActiveRecord::Relation

Find other error types that occurred near this occurrence

Parameters:

  • window_minutes (Integer) (defaults to: 5)

    Time window in minutes (default: 5)

Returns:

  • (ActiveRecord::Relation)

    ErrorLog records of co-occurring errors



44
45
46
47
# File 'app/models/rails_error_dashboard/error_occurrence.rb', line 44

def co_occurring_error_types(window_minutes: 5)
  occurrence_ids = nearby_occurrences(window_minutes: window_minutes).pluck(:error_log_id)
  ErrorLog.where(id: occurrence_ids).where.not(error_type: error_log.error_type).distinct
end

#nearby_occurrences(window_minutes: 5) ⇒ ActiveRecord::Relation

Find occurrences within a time window around this occurrence

Parameters:

  • window_minutes (Integer) (defaults to: 5)

    Time window in minutes (default: 5)

Returns:

  • (ActiveRecord::Relation)

    Other occurrences in the time window



31
32
33
34
35
36
37
38
39
# File 'app/models/rails_error_dashboard/error_occurrence.rb', line 31

def nearby_occurrences(window_minutes: 5)
  window = window_minutes.minutes
  start_time = occurred_at - window
  end_time = occurred_at + window

  self.class
    .in_time_window(start_time, end_time)
    .where.not(id: id) # Exclude self
end