diff options
Diffstat (limited to 'lib/error_tracking')
-rw-r--r-- | lib/error_tracking/sentry_client.rb | 11 | ||||
-rw-r--r-- | lib/error_tracking/sentry_client/event.rb | 2 | ||||
-rw-r--r-- | lib/error_tracking/sentry_client/issue.rb | 12 |
3 files changed, 20 insertions, 5 deletions
diff --git a/lib/error_tracking/sentry_client.rb b/lib/error_tracking/sentry_client.rb index 029389ab5d6..713cec7a7d6 100644 --- a/lib/error_tracking/sentry_client.rb +++ b/lib/error_tracking/sentry_client.rb @@ -10,6 +10,7 @@ module ErrorTracking Error = Class.new(StandardError) MissingKeysError = Class.new(StandardError) + InvalidFieldValueError = Class.new(StandardError) ResponseInvalidSizeError = Class.new(StandardError) RESPONSE_SIZE_LIMIT = 1.megabyte @@ -110,5 +111,15 @@ module ErrorTracking def raise_error(message) raise SentryClient::Error, message end + + def ensure_numeric!(field, value) + return value if /\A\d+\z/.match?(value) + + raise_invalid_field_value!(field, "#{value.inspect} is not numeric") + end + + def raise_invalid_field_value!(field, message) + raise InvalidFieldValueError, %(Sentry API response contains invalid value for field "#{field}": #{message}) + end end end diff --git a/lib/error_tracking/sentry_client/event.rb b/lib/error_tracking/sentry_client/event.rb index 1db31abeeb2..d8ae81f5411 100644 --- a/lib/error_tracking/sentry_client/event.rb +++ b/lib/error_tracking/sentry_client/event.rb @@ -16,7 +16,7 @@ module ErrorTracking Gitlab::ErrorTracking::ErrorEvent.new( project_id: event['projectID'], - issue_id: event['groupID'], + issue_id: ensure_numeric!('issue_id', event['groupID']), date_received: event['dateReceived'], stack_trace_entries: stack_trace ) diff --git a/lib/error_tracking/sentry_client/issue.rb b/lib/error_tracking/sentry_client/issue.rb index 3c846eb0635..5e2e0787a3f 100644 --- a/lib/error_tracking/sentry_client/issue.rb +++ b/lib/error_tracking/sentry_client/issue.rb @@ -114,8 +114,10 @@ module ErrorTracking end def map_to_error(issue) + id = ensure_numeric!('id', issue.fetch('id')) + Gitlab::ErrorTracking::Error.new( - id: issue.fetch('id'), + id: id, first_seen: issue.fetch('firstSeen', nil), last_seen: issue.fetch('lastSeen', nil), title: issue.fetch('title', nil), @@ -124,7 +126,7 @@ module ErrorTracking count: issue.fetch('count', nil), message: issue.dig('metadata', 'value'), culprit: issue.fetch('culprit', nil), - external_url: issue_url(issue.fetch('id')), + external_url: issue_url(id), short_id: issue.fetch('shortId', nil), status: issue.fetch('status', nil), frequency: issue.dig('stats', '24h'), @@ -135,8 +137,10 @@ module ErrorTracking end def map_to_detailed_error(issue) + id = ensure_numeric!('id', issue.fetch('id')) + Gitlab::ErrorTracking::DetailedError.new( - id: issue.fetch('id'), + id: id, first_seen: issue.fetch('firstSeen', nil), last_seen: issue.fetch('lastSeen', nil), tags: extract_tags(issue), @@ -146,7 +150,7 @@ module ErrorTracking count: issue.fetch('count', nil), message: issue.dig('metadata', 'value'), culprit: issue.fetch('culprit', nil), - external_url: issue_url(issue.fetch('id')), + external_url: issue_url(id), external_base_url: project_url, short_id: issue.fetch('shortId', nil), status: issue.fetch('status', nil), |