diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-15 15:09:20 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-15 15:09:20 +0000 |
commit | 9440c17f554424cc77aff8afadc61adbe23524d1 (patch) | |
tree | bc2b4213d845e5fd6d43eb71d21cfce28c81e440 /app/models/error_tracking | |
parent | 3e0c035fe3a10436be36b4e22a4986479821b8e4 (diff) | |
download | gitlab-ce-9440c17f554424cc77aff8afadc61adbe23524d1.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/error_tracking')
-rw-r--r-- | app/models/error_tracking/error_event.rb | 54 |
1 files changed, 1 insertions, 53 deletions
diff --git a/app/models/error_tracking/error_event.rb b/app/models/error_tracking/error_event.rb index 18c1467e6f6..3ee82b219dc 100644 --- a/app/models/error_tracking/error_event.rb +++ b/app/models/error_tracking/error_event.rb @@ -15,7 +15,7 @@ class ErrorTracking::ErrorEvent < ApplicationRecord validates :occurred_at, presence: true def stacktrace - @stacktrace ||= build_stacktrace + @stacktrace ||= ErrorTracking::StacktraceBuilder.new(payload).stacktrace end # For compatibility with sentry integration @@ -30,56 +30,4 @@ class ErrorTracking::ErrorEvent < ApplicationRecord def release payload.dig('release') end - - private - - def build_stacktrace - raw_stacktrace = find_stacktrace_from_payload - - return [] unless raw_stacktrace - - raw_stacktrace.map do |entry| - { - 'lineNo' => entry['lineno'], - 'context' => build_stacktrace_context(entry), - 'filename' => entry['filename'], - 'function' => entry['function'], - 'colNo' => 0 # we don't support colNo yet. - } - end - end - - def find_stacktrace_from_payload - exception_entry = payload.dig('exception') - - if exception_entry - exception_values = exception_entry.dig('values') - stack_trace_entry = exception_values&.detect { |h| h['stacktrace'].present? } - stack_trace_entry&.dig('stacktrace', 'frames') - end - end - - def build_stacktrace_context(entry) - context = [] - error_line = entry['context_line'] - error_line_no = entry['lineno'] - pre_context = entry['pre_context'] - post_context = entry['post_context'] - - context += lines_with_position(pre_context, error_line_no - pre_context.size) if pre_context - context += lines_with_position([error_line], error_line_no) - context += lines_with_position(post_context, error_line_no + 1) if post_context - - context.reject(&:blank?) - end - - def lines_with_position(lines, position) - return [] if lines.blank? - - lines.map.with_index do |line, index| - next unless line - - [position + index, line] - end - end end |