Class: ErrorTracking::Error

Inherits:
ApplicationRecord show all
Includes:
Sortable
Defined in:
app/models/error_tracking/error.rb

Constant Summary

Constants inherited from ApplicationRecord

ApplicationRecord::MAX_PLUCK

Constants included from ResetOnUnionError

ResetOnUnionError::MAX_RESET_PERIOD

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order

Methods included from SensitiveSerializableHash

#serializable_hash

Class Method Details

.report_error(name:, description:, actor:, platform:, timestamp:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/error_tracking/error.rb', line 33

def self.report_error(name:, description:, actor:, platform:, timestamp:)
  safe_find_or_create_by(
    name: name,
    actor: actor,
    platform: platform
  ).tap do |error|
    error.update!(
      # Description can contain object id, so it can't be
      # used as a group criteria for similar errors.
      description: description,
      last_seen_at: timestamp
    )
  end
end

.sort_by_attribute(method) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/error_tracking/error.rb', line 48

def self.sort_by_attribute(method)
  case method.to_s
  when 'last_seen'
    order(last_seen_at: :desc)
  when 'first_seen'
    order(first_seen_at: :desc)
  when 'frequency'
    order(events_count: :desc)
  else
    order_id_desc
  end
end

Instance Method Details

#titleObject



61
62
63
64
65
66
67
# File 'app/models/error_tracking/error.rb', line 61

def title
  if description.present?
    "#{name} #{description}"
  else
    name
  end
end

#title_truncatedObject



69
70
71
# File 'app/models/error_tracking/error.rb', line 69

def title_truncated
  title.truncate(64)
end

#to_sentry_detailed_errorObject

For compatibility with sentry integration



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'app/models/error_tracking/error.rb', line 88

def to_sentry_detailed_error
  Gitlab::ErrorTracking::DetailedError.new(
    id: id,
    title: title_truncated,
    message: description,
    culprit: actor,
    first_seen: first_seen_at.to_s,
    last_seen: last_seen_at.to_s,
    count: events_count,
    user_count: 0, # we don't support user count yet.
    project_id: project.id,
    status: status,
    tags: { level: nil, logger: nil },
    external_url: external_url,
    external_base_url: external_base_url,
    integrated: true,
    first_release_version: first_event&.release,
    last_release_version: last_event&.release
  )
end

#to_sentry_errorObject

For compatibility with sentry integration



74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/error_tracking/error.rb', line 74

def to_sentry_error
  Gitlab::ErrorTracking::Error.new(
    id: id,
    title: title_truncated,
    message: description,
    culprit: actor,
    first_seen: first_seen_at,
    last_seen: last_seen_at,
    status: status,
    count: events_count
  )
end