diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-19 04:45:44 +0300 |
commit | 85dc423f7090da0a52c73eb66faf22ddb20efff9 (patch) | |
tree | 9160f299afd8c80c038f08e1545be119f5e3f1e1 /lib/gitlab/error_tracking/processor/grpc_error_processor.rb | |
parent | 15c2c8c66dbe422588e5411eee7e68f1fa440bb8 (diff) |
Add latest changes from gitlab-org/gitlab@13-4-stable-ee
Diffstat (limited to 'lib/gitlab/error_tracking/processor/grpc_error_processor.rb')
-rw-r--r-- | lib/gitlab/error_tracking/processor/grpc_error_processor.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/lib/gitlab/error_tracking/processor/grpc_error_processor.rb b/lib/gitlab/error_tracking/processor/grpc_error_processor.rb new file mode 100644 index 00000000000..871e9c4b7c8 --- /dev/null +++ b/lib/gitlab/error_tracking/processor/grpc_error_processor.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +module Gitlab + module ErrorTracking + module Processor + class GrpcErrorProcessor < ::Raven::Processor + DEBUG_ERROR_STRING_REGEX = RE2('(.*) debug_error_string:(.*)') + + def process(value) + process_first_exception_value(value) + process_custom_fingerprint(value) + + value + end + + # Sentry can report multiple exceptions in an event. Sanitize + # only the first one since that's what is used for grouping. + def process_first_exception_value(value) + exceptions = value.dig(:exception, :values) + + return unless exceptions.is_a?(Array) + + entry = exceptions.first + + return unless entry.is_a?(Hash) + + exception_type = entry[:type] + raw_message = entry[:value] + + return unless exception_type&.start_with?('GRPC::') + return unless raw_message.present? + + message, debug_str = split_debug_error_string(raw_message) + + entry[:value] = message if message + extra = value[:extra] || {} + extra[:grpc_debug_error_string] = debug_str if debug_str + end + + def process_custom_fingerprint(value) + fingerprint = value[:fingerprint] + + return value unless custom_grpc_fingerprint?(fingerprint) + + message, _ = split_debug_error_string(fingerprint[1]) + fingerprint[1] = message if message + end + + private + + def custom_grpc_fingerprint?(fingerprint) + fingerprint.is_a?(Array) && fingerprint.length == 2 && fingerprint[0].start_with?('GRPC::') + end + + def split_debug_error_string(message) + return unless message + + match = DEBUG_ERROR_STRING_REGEX.match(message) + + return unless match + + [match[1], match[2]] + end + end + end + end +end |