diff options
Diffstat (limited to 'app/models/error_tracking')
-rw-r--r-- | app/models/error_tracking/client_key.rb | 6 | ||||
-rw-r--r-- | app/models/error_tracking/error.rb | 25 | ||||
-rw-r--r-- | app/models/error_tracking/project_error_tracking_setting.rb | 2 |
3 files changed, 28 insertions, 5 deletions
diff --git a/app/models/error_tracking/client_key.rb b/app/models/error_tracking/client_key.rb index 9d12c0ed6f1..8e59f6f9ecb 100644 --- a/app/models/error_tracking/client_key.rb +++ b/app/models/error_tracking/client_key.rb @@ -14,9 +14,13 @@ class ErrorTracking::ClientKey < ApplicationRecord find_by(public_key: key) end + def sentry_dsn + @sentry_dsn ||= ErrorTracking::Collector::Dsn.build_url(public_key, project_id) + end + private def generate_key - self.public_key = "glet_#{SecureRandom.hex}" + self.public_key ||= "glet_#{SecureRandom.hex}" end end diff --git a/app/models/error_tracking/error.rb b/app/models/error_tracking/error.rb index 32932c4d045..39ecc487806 100644 --- a/app/models/error_tracking/error.rb +++ b/app/models/error_tracking/error.rb @@ -1,6 +1,8 @@ # frozen_string_literal: true class ErrorTracking::Error < ApplicationRecord + include Sortable + belongs_to :project has_many :events, class_name: 'ErrorTracking::ErrorEvent' @@ -22,11 +24,28 @@ class ErrorTracking::Error < ApplicationRecord def self.report_error(name:, description:, actor:, platform:, timestamp:) safe_find_or_create_by( name: name, - description: description, actor: actor, platform: platform - ) do |error| - error.update!(last_seen_at: timestamp) + ).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 + + 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 diff --git a/app/models/error_tracking/project_error_tracking_setting.rb b/app/models/error_tracking/project_error_tracking_setting.rb index c5a77427588..dd5ce9f7387 100644 --- a/app/models/error_tracking/project_error_tracking_setting.rb +++ b/app/models/error_tracking/project_error_tracking_setting.rb @@ -51,7 +51,7 @@ module ErrorTracking end def integrated_client? - integrated && ::Feature.enabled?(:integrated_error_tracking, project) + integrated end def api_url=(value) |