diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-20 12:55:51 +0300 |
commit | e8d2c2579383897a1dd7f9debd359abe8ae8373d (patch) | |
tree | c42be41678c2586d49a75cabce89322082698334 /app/services/error_tracking | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'app/services/error_tracking')
-rw-r--r-- | app/services/error_tracking/collect_error_service.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/services/error_tracking/collect_error_service.rb b/app/services/error_tracking/collect_error_service.rb new file mode 100644 index 00000000000..bc1f238d81f --- /dev/null +++ b/app/services/error_tracking/collect_error_service.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module ErrorTracking + class CollectErrorService < ::BaseService + def execute + # Error is a way to group events based on common data like name or cause + # of exception. We need to keep a sane balance here between taking too little + # and too much data into group logic. + error = project.error_tracking_errors.report_error( + name: exception['type'], # Example: ActionView::MissingTemplate + description: exception['value'], # Example: Missing template posts/show in... + actor: event['transaction'], # Example: PostsController#show + platform: event['platform'], # Example: ruby + timestamp: event['timestamp'] + ) + + # The payload field contains all the data on error including stacktrace in jsonb. + # Together with occured_at these are 2 main attributes that we need to save here. + error.events.create!( + environment: event['environment'], + description: exception['type'], + level: event['level'], + occurred_at: event['timestamp'], + payload: event + ) + end + + private + + def event + params[:event] + end + + def exception + event['exception']['values'].first + end + end +end |