Class: ErrorTracking::Collector::SentryRequestParser

Inherits:
Object
  • Object
show all
Defined in:
lib/error_tracking/collector/sentry_request_parser.rb

Class Method Summary collapse

Class Method Details

.parse(request) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/error_tracking/collector/sentry_request_parser.rb', line 6

def self.parse(request)
  body = request.body.read

  # 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