Class: Rox::Core::ErrorReporter
- Inherits:
-
Object
- Object
- Rox::Core::ErrorReporter
- Defined in:
- lib/rox/core/reporting/error_reporter.rb
Constant Summary collapse
- BUGSNAG_NOTIFY_URL =
'https://notify.bugsnag.com'.freeze
- STACK_TRACE_LINE_REGEX =
/^((?:[a-zA-Z]:)?[^:]+):(\d+)(?::in `([^']+)')?$/
Instance Method Summary collapse
- #add_api_key(payload) ⇒ Object
- #add_app(ev) ⇒ Object
- #add_event(message, ex, stack, events) ⇒ Object
- #add_events(message, ex, stack, payload) ⇒ Object
- #add_exceptions(message, ex, stack, ev) ⇒ Object
- #add_metadata(message, ev) ⇒ Object
- #add_notifier(payload) ⇒ Object
- #add_payload_version(ev) ⇒ Object
- #add_user(id, rollout_key, ev) ⇒ Object
- #create_payload(message, ex, stack) ⇒ Object
-
#initialize(request, device_properties, buid) ⇒ ErrorReporter
constructor
A new instance of ErrorReporter.
- #parse_stack_trace(stack_trace) ⇒ Object
- #report(message, ex) ⇒ Object
- #send_error(payload) ⇒ Object
Constructor Details
#initialize(request, device_properties, buid) ⇒ ErrorReporter
Returns a new instance of ErrorReporter.
8 9 10 11 12 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 8 def initialize(request, device_properties, buid) @request = request @device_properties = device_properties @buid = buid end |
Instance Method Details
#add_api_key(payload) ⇒ Object
64 65 66 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 64 def add_api_key(payload) payload['apiKey'] = '9569ec14f61546c6aa2a97856492bf4d' end |
#add_app(ev) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 122 def add_app(ev) app = { 'releaseStage' => @device_properties.rollout_environment, 'version' => @device_properties.lib_version } ev['app'] = app end |
#add_event(message, ex, stack, events) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 74 def add_event(, ex, stack, events) ev = {} add_payload_version(ev) add_exceptions(, ex, stack, ev) add_user('id', @device_properties.rollout_key, ev) (, ev) add_app(ev) events << ev end |
#add_events(message, ex, stack, payload) ⇒ Object
68 69 70 71 72 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 68 def add_events(, ex, stack, payload) evs = [] add_event(, ex, stack, evs) payload['events'] = evs end |
#add_exceptions(message, ex, stack, ev) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 104 def add_exceptions(, ex, stack, ev) exceptions = [] exception = {} if ex.nil? exception['errorClass'] = exception['message'] = exception['stacktrace'] = [] else exception['errorClass'] = ex. exception['message'] = ex. exception['stacktrace'] = stack end exceptions.append(exception) ev['exceptions'] = exceptions end |
#add_metadata(message, ev) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 50 def (, ev) inner_data = { 'message' => , 'deviceId' => @device_properties.distinct_id, 'buid' => @buid.to_s } = { 'data' => inner_data } ev['metaData'] = end |
#add_notifier(payload) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 89 def add_notifier(payload) notifier = { 'name' => 'Rollout Ruby SDK', 'version' => @device_properties.lib_version } payload['notifier'] = notifier end |
#add_payload_version(ev) ⇒ Object
85 86 87 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 85 def add_payload_version(ev) ev['payloadVersion'] = 2 end |
#add_user(id, rollout_key, ev) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 97 def add_user(id, rollout_key, ev) user = { id => rollout_key } ev['user'] = user end |
#create_payload(message, ex, stack) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 41 def create_payload(, ex, stack) payload = {} add_api_key(payload) add_notifier(payload) add_events(, ex, stack, payload) payload end |
#parse_stack_trace(stack_trace) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 132 def parse_stack_trace(stack_trace) stack = [] stack_trace.each do |line| match = line.match(STACK_TRACE_LINE_REGEX) next if match.nil? file = match[1] line_str = match[2] func = match[3] stack << { 'file' => file, 'method' => func, 'lineNumber' => line_str.to_i, 'columnNumber' => 0 } end stack end |
#report(message, ex) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 14 def report(, ex) return if @device_properties.rollout_environment == 'LOCAL' Logging.logger.error("Error report: #{}", ex) begin stack_trace = ex.nil? ? caller : ex.backtrace stack = parse_stack_trace(stack_trace) payload = create_payload(, ex, stack) rescue StandardError => e Logging.logger.error('failed to create bugsnag json payload of the error', e) else Thread.new { send_error(payload) } end end |
#send_error(payload) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rox/core/reporting/error_reporter.rb', line 30 def send_error(payload) Logging.logger.debug('Sending bugsnag error report...') begin @request.send_post(ErrorReporter::BUGSNAG_NOTIFY_URL, payload) Logging.logger.debug('Bugsnag error report was sent') rescue StandardError => ex Logging.logger.error('Failed to send bugsnag error ', ex) end end |