diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /app/models/error_tracking | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'app/models/error_tracking')
-rw-r--r-- | app/models/error_tracking/error.rb | 15 | ||||
-rw-r--r-- | app/models/error_tracking/error_event.rb | 4 | ||||
-rw-r--r-- | app/models/error_tracking/project_error_tracking_setting.rb | 25 |
3 files changed, 42 insertions, 2 deletions
diff --git a/app/models/error_tracking/error.rb b/app/models/error_tracking/error.rb index 39ecc487806..2d6a4694def 100644 --- a/app/models/error_tracking/error.rb +++ b/app/models/error_tracking/error.rb @@ -7,6 +7,14 @@ class ErrorTracking::Error < ApplicationRecord has_many :events, class_name: 'ErrorTracking::ErrorEvent' + has_one :first_event, + -> { order(id: :asc) }, + class_name: 'ErrorTracking::ErrorEvent' + + has_one :last_event, + -> { order(id: :desc) }, + class_name: 'ErrorTracking::ErrorEvent' + scope :for_status, -> (status) { where(status: status) } validates :project, presence: true @@ -90,7 +98,10 @@ class ErrorTracking::Error < ApplicationRecord status: status, tags: { level: nil, logger: nil }, external_url: external_url, - external_base_url: external_base_url + external_base_url: external_base_url, + integrated: true, + first_release_version: first_event&.release, + last_release_version: last_event&.release ) end @@ -106,6 +117,6 @@ class ErrorTracking::Error < ApplicationRecord # For compatibility with sentry integration def external_base_url - Gitlab::Routing.url_helpers.root_url + Gitlab::Routing.url_helpers.project_url(project) end end diff --git a/app/models/error_tracking/error_event.rb b/app/models/error_tracking/error_event.rb index 4de13de7e2e..686518a39fb 100644 --- a/app/models/error_tracking/error_event.rb +++ b/app/models/error_tracking/error_event.rb @@ -22,6 +22,10 @@ class ErrorTracking::ErrorEvent < ApplicationRecord ) end + def release + payload.dig('release') + end + private def build_stacktrace diff --git a/app/models/error_tracking/project_error_tracking_setting.rb b/app/models/error_tracking/project_error_tracking_setting.rb index dd5ce9f7387..25f812645b1 100644 --- a/app/models/error_tracking/project_error_tracking_setting.rb +++ b/app/models/error_tracking/project_error_tracking_setting.rb @@ -46,6 +46,11 @@ module ErrorTracking after_save :clear_reactive_cache! + # When a user enables the integrated error tracking + # we want to immediately provide them with a first + # working client key so they have a DSN for Sentry SDK. + after_save :create_client_key! + def sentry_enabled enabled && !integrated_client? end @@ -54,6 +59,12 @@ module ErrorTracking integrated end + def gitlab_dsn + strong_memoize(:gitlab_dsn) do + client_key&.sentry_dsn + end + end + def api_url=(value) super clear_memoization(:api_url_slugs) @@ -236,5 +247,19 @@ module ErrorTracking errors.add(:project, 'is a required field') end end + + def client_key + # Project can have multiple client keys. + # However for UI simplicity we render the first active one for user. + # In future we should make it possible to manage client keys from UI. + # Issue https://gitlab.com/gitlab-org/gitlab/-/issues/329596 + project.error_tracking_client_keys.active.first + end + + def create_client_key! + if enabled? && integrated_client? && !client_key + project.error_tracking_client_keys.create! + end + end end end |