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 /lib/error_tracking | |
parent | fc845b37ec3a90aaa719975f607740c22ba6a113 (diff) |
Add latest changes from gitlab-org/gitlab@14-1-stable-eev14.1.0-rc42
Diffstat (limited to 'lib/error_tracking')
-rw-r--r-- | lib/error_tracking/collector/sentry_request_parser.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/error_tracking/collector/sentry_request_parser.rb b/lib/error_tracking/collector/sentry_request_parser.rb new file mode 100644 index 00000000000..29e4cc8976f --- /dev/null +++ b/lib/error_tracking/collector/sentry_request_parser.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module ErrorTracking + module Collector + class SentryRequestParser + def self.parse(request) + # Request body can be "" or "gzip". + # If later then body was compressed with Zlib.gzip + encoding = request.headers['Content-Encoding'] + + body = if encoding == 'gzip' + Zlib.gunzip(request.body.read) + else + request.body.read + end + + # Request body contains 3 json objects merged together in one StringIO. + # We need to separate and parse them into array of hash objects. + json_objects = [] + parser = Yajl::Parser.new + + parser.parse(body) do |json_object| + json_objects << json_object + end + + # The request contains 3 objects: sentry metadata, type data and event data. + # We need only last two. Type to decide what to do with the request. + # And event data as it contains all information about the exception. + _, type, event = json_objects + + { + request_type: type['type'], + event: event + } + end + end + end +end |