diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 00:07:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-08 00:07:50 +0300 |
commit | d203316c80aa27cf747aa29df9f7c2d374965b5f (patch) | |
tree | aab5cde76fbf19a2639f6f9f3cb4f2acdc95f803 /lib/sentry | |
parent | 8dafc3b65aeb8f50fdfc38fb98d96c3db9e2f607 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/sentry')
-rw-r--r-- | lib/sentry/client.rb | 39 | ||||
-rw-r--r-- | lib/sentry/client/event.rb | 43 |
2 files changed, 44 insertions, 38 deletions
diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb index 211c828ccc3..e3b8305b664 100644 --- a/lib/sentry/client.rb +++ b/lib/sentry/client.rb @@ -2,6 +2,7 @@ module Sentry class Client + include Sentry::Client::Event include Sentry::Client::Projects include Sentry::Client::Issue @@ -24,12 +25,6 @@ module Sentry @token = token end - def issue_latest_event(issue_id:) - latest_event = get_issue_latest_event(issue_id: issue_id) - - map_to_event(latest_event) - end - def list_issues(**keyword_args) response = get_issues(keyword_args) @@ -115,10 +110,6 @@ module Sentry }.compact end - def get_issue_latest_event(issue_id:) - http_get(issue_latest_event_api_url(issue_id))[:body] - end - def handle_request_exceptions yield rescue Gitlab::HTTP::Error => e @@ -149,13 +140,6 @@ module Sentry raise Client::Error, message end - def issue_latest_event_api_url(issue_id) - latest_event_url = URI(@url) - latest_event_url.path = "/api/0/issues/#{issue_id}/events/latest/" - - latest_event_url - end - def issues_api_url issues_url = URI(@url + '/issues/') issues_url.path.squeeze!('/') @@ -188,27 +172,6 @@ module Sentry uri end - def map_to_event(event) - stack_trace = parse_stack_trace(event) - - Gitlab::ErrorTracking::ErrorEvent.new( - issue_id: event.dig('groupID'), - date_received: event.dig('dateReceived'), - stack_trace_entries: stack_trace - ) - end - - def parse_stack_trace(event) - exception_entry = event.dig('entries')&.detect { |h| h['type'] == 'exception' } - return [] unless exception_entry - - exception_values = exception_entry.dig('data', 'values') - stack_trace_entry = exception_values&.detect { |h| h['stacktrace'].present? } - return [] unless stack_trace_entry - - stack_trace_entry.dig('stacktrace', 'frames') || [] - end - def map_to_error(issue) Gitlab::ErrorTracking::Error.new( id: issue.fetch('id'), diff --git a/lib/sentry/client/event.rb b/lib/sentry/client/event.rb new file mode 100644 index 00000000000..8bcada5a9ce --- /dev/null +++ b/lib/sentry/client/event.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +module Sentry + class Client + module Event + def issue_latest_event(issue_id:) + latest_event = http_get(issue_latest_event_api_url(issue_id))[:body] + + map_to_event(latest_event) + end + + private + + def issue_latest_event_api_url(issue_id) + latest_event_url = URI(url) + latest_event_url.path = "/api/0/issues/#{issue_id}/events/latest/" + + latest_event_url + end + + def map_to_event(event) + stack_trace = parse_stack_trace(event) + + Gitlab::ErrorTracking::ErrorEvent.new( + issue_id: event.dig('groupID'), + date_received: event.dig('dateReceived'), + stack_trace_entries: stack_trace + ) + end + + def parse_stack_trace(event) + exception_entry = event.dig('entries')&.detect { |h| h['type'] == 'exception' } + return [] unless exception_entry + + exception_values = exception_entry.dig('data', 'values') + stack_trace_entry = exception_values&.detect { |h| h['stacktrace'].present? } + return [] unless stack_trace_entry + + stack_trace_entry.dig('stacktrace', 'frames') || [] + end + end + end +end |