rollbar 0.10.7 → 0.10.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +4 -0
- data/lib/rollbar.rb +119 -20
- data/lib/rollbar/version.rb +1 -1
- data/spec/rollbar_spec.rb +45 -1
- metadata +2 -3
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
**0.10.8**
|
4
|
+
- Better handling of internal errors. Internal errors (errors that occur while reporting something to Rollbar) are now themselves reported to Rollbar. If that fails, a failsafe message will be reported, and if that fails, the error will be logged as it is now.
|
5
|
+
- Fix bug reporting exceptions with backtraces containing frames that don't match our regex.
|
6
|
+
|
3
7
|
**0.10.7**
|
4
8
|
- Add ability to report form validation errors
|
5
9
|
- Add MIT license to gemspec
|
data/lib/rollbar.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'net/https'
|
2
|
+
|
2
3
|
require 'securerandom' if defined?(SecureRandom)
|
3
4
|
require 'socket'
|
4
5
|
require 'thread'
|
@@ -89,7 +90,7 @@ module Rollbar
|
|
89
90
|
log_instance_link(data)
|
90
91
|
data
|
91
92
|
rescue => e
|
92
|
-
|
93
|
+
report_internal_error(e)
|
93
94
|
'error'
|
94
95
|
end
|
95
96
|
|
@@ -113,7 +114,7 @@ module Rollbar
|
|
113
114
|
log_instance_link(data)
|
114
115
|
data
|
115
116
|
rescue => e
|
116
|
-
|
117
|
+
report_internal_error(e)
|
117
118
|
'error'
|
118
119
|
end
|
119
120
|
|
@@ -140,7 +141,7 @@ module Rollbar
|
|
140
141
|
send_payload(payload)
|
141
142
|
end
|
142
143
|
rescue => e
|
143
|
-
|
144
|
+
log_error "[Rollbar] Error processing payload: #{e}"
|
144
145
|
end
|
145
146
|
end
|
146
147
|
|
@@ -154,9 +155,9 @@ module Rollbar
|
|
154
155
|
require 'rollbar/rake' if defined?(Rake)
|
155
156
|
require 'rollbar/better_errors' if defined?(BetterErrors)
|
156
157
|
end
|
157
|
-
|
158
|
+
|
158
159
|
def log_instance_link(data)
|
159
|
-
|
160
|
+
log_info "[Rollbar] Details: #{configuration.web_base}/instance/uuid?uuid=#{data[:uuid]} (only available if report was successful)"
|
160
161
|
end
|
161
162
|
|
162
163
|
def ignored?(exception)
|
@@ -199,7 +200,11 @@ module Rollbar
|
|
199
200
|
frames = exception.backtrace.map { |frame|
|
200
201
|
# parse the line
|
201
202
|
match = frame.match(/(.*):(\d+)(?::in `([^']+)')?/)
|
202
|
-
|
203
|
+
if match
|
204
|
+
{ :filename => match[1], :lineno => match[2].to_i, :method => match[3] }
|
205
|
+
else
|
206
|
+
{ :filename => "<unknown>", :lineno => 0, :method => frame }
|
207
|
+
end
|
203
208
|
}
|
204
209
|
# reverse so that the order is as rollbar expects
|
205
210
|
frames.reverse!
|
@@ -241,7 +246,7 @@ module Rollbar
|
|
241
246
|
end
|
242
247
|
|
243
248
|
def do_write_payload(payload)
|
244
|
-
|
249
|
+
log_info '[Rollbar] Writing payload to file'
|
245
250
|
|
246
251
|
begin
|
247
252
|
unless @file
|
@@ -250,9 +255,9 @@ module Rollbar
|
|
250
255
|
|
251
256
|
@file.puts payload
|
252
257
|
@file.flush
|
253
|
-
|
258
|
+
log_info "[Rollbar] Success"
|
254
259
|
rescue IOError => e
|
255
|
-
|
260
|
+
log_error "[Rollbar] Error opening/writing to file: #{e}"
|
256
261
|
end
|
257
262
|
end
|
258
263
|
|
@@ -260,20 +265,20 @@ module Rollbar
|
|
260
265
|
req = EventMachine::HttpRequest.new(configuration.endpoint).post(:body => payload)
|
261
266
|
req.callback do
|
262
267
|
if req.response_header.status == 200
|
263
|
-
|
268
|
+
log_info '[Rollbar] Success'
|
264
269
|
else
|
265
|
-
|
266
|
-
|
270
|
+
log_warning "[Rollbar] Got unexpected status code from Rollbar.io api: #{req.response_header.status}"
|
271
|
+
log_info "[Rollbar] Response: #{req.response}"
|
267
272
|
end
|
268
273
|
end
|
269
274
|
req.errback do
|
270
|
-
|
271
|
-
|
275
|
+
log_warning "[Rollbar] Call to API failed, status code: #{req.response_header.status}"
|
276
|
+
log_info "[Rollbar] Error's response: #{req.response}"
|
272
277
|
end
|
273
278
|
end
|
274
279
|
|
275
280
|
def send_payload(payload)
|
276
|
-
|
281
|
+
log_info '[Rollbar] Sending payload'
|
277
282
|
|
278
283
|
if configuration.use_eventmachine
|
279
284
|
send_payload_using_eventmachine(payload)
|
@@ -292,15 +297,15 @@ module Rollbar
|
|
292
297
|
response = http.request(request)
|
293
298
|
|
294
299
|
if response.code == '200'
|
295
|
-
|
300
|
+
log_info '[Rollbar] Success'
|
296
301
|
else
|
297
|
-
|
298
|
-
|
302
|
+
log_warning "[Rollbar] Got unexpected status code from Rollbar api: #{response.code}"
|
303
|
+
log_info "[Rollbar] Response: #{response.body}"
|
299
304
|
end
|
300
305
|
end
|
301
306
|
|
302
307
|
def schedule_payload(payload)
|
303
|
-
|
308
|
+
log_info '[Rollbar] Scheduling payload'
|
304
309
|
|
305
310
|
if configuration.use_async
|
306
311
|
unless configuration.async_handler
|
@@ -375,11 +380,105 @@ module Rollbar
|
|
375
380
|
|
376
381
|
@queue.push(payload)
|
377
382
|
else
|
378
|
-
|
383
|
+
log_warning '[Rollbar] girl_friday not found to handle async call, falling back to Thread'
|
379
384
|
Thread.new { process_payload(payload) }
|
380
385
|
end
|
381
386
|
end
|
387
|
+
|
388
|
+
# wrappers around logger methods
|
389
|
+
def log_error(message)
|
390
|
+
begin
|
391
|
+
logger.error message
|
392
|
+
rescue => e
|
393
|
+
puts "[Rollbar] Error logging error:"
|
394
|
+
puts "[Rollbar] #{message}"
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
def log_info(message)
|
399
|
+
begin
|
400
|
+
logger.info message
|
401
|
+
rescue => e
|
402
|
+
puts "[Rollbar] Error logging info:"
|
403
|
+
puts "[Rollbar] #{message}"
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
def log_warning(message)
|
408
|
+
begin
|
409
|
+
logger.warn message
|
410
|
+
rescue => e
|
411
|
+
puts "[Rollbar] Error logging warning:"
|
412
|
+
puts "[Rollbar] #{message}"
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
# Reports an internal error in the Rollbar library. This will be reported within the configured
|
417
|
+
# Rollbar project. We'll first attempt to provide a report including the exception traceback.
|
418
|
+
# If that fails, we'll fall back to a more static failsafe response.
|
419
|
+
def report_internal_error(exception)
|
420
|
+
log_error "[Rollbar] Reporting internal error encountered while sending data to Rollbar."
|
421
|
+
|
422
|
+
begin
|
423
|
+
data = exception_data(exception, 'error')
|
424
|
+
rescue => e
|
425
|
+
send_failsafe("error in exception_data", e)
|
426
|
+
return
|
427
|
+
end
|
428
|
+
|
429
|
+
data[:internal] = true
|
430
|
+
|
431
|
+
begin
|
432
|
+
payload = build_payload(data)
|
433
|
+
rescue => e
|
434
|
+
send_failsafe("error in build_payload", e)
|
435
|
+
return
|
436
|
+
end
|
437
|
+
|
438
|
+
begin
|
439
|
+
schedule_payload(payload)
|
440
|
+
rescue => e
|
441
|
+
send_failsafe("erorr in schedule_payload", e)
|
442
|
+
return
|
443
|
+
end
|
444
|
+
|
445
|
+
begin
|
446
|
+
log_instance_link(data)
|
447
|
+
rescue => e
|
448
|
+
send_failsafe("error logging instance link", e)
|
449
|
+
return
|
450
|
+
end
|
451
|
+
end
|
452
|
+
|
453
|
+
def send_failsafe(message, exception)
|
454
|
+
log_error "[Rollbar] Sending failsafe response."
|
455
|
+
log_error "[Rollbar] #{message} #{exception}"
|
456
|
+
|
457
|
+
config = configuration
|
458
|
+
environment = config.environment
|
459
|
+
|
460
|
+
failsafe_payload = <<-eos
|
461
|
+
{"access_token": "#{config.access_token}",
|
462
|
+
"data": {
|
463
|
+
"level": "error",
|
464
|
+
"environment": "#{config.environment}",
|
465
|
+
"body": { "message": { "body": "Failsafe from rollbar-gem: #{message}" } },
|
466
|
+
"notifier": { "name": "rollbar-gem", "version": "#{VERSION}" },
|
467
|
+
"internal": true,
|
468
|
+
"failsafe": true
|
469
|
+
}
|
470
|
+
}
|
471
|
+
eos
|
472
|
+
|
473
|
+
begin
|
474
|
+
schedule_payload(failsafe_payload)
|
475
|
+
rescue => e
|
476
|
+
log_error "[Rollbar] Error sending failsafe : #{e}"
|
477
|
+
end
|
478
|
+
end
|
479
|
+
|
382
480
|
end
|
481
|
+
|
383
482
|
end
|
384
483
|
|
385
484
|
# Setting Ratchetio as an alias to Rollbar for ratchetio-gem backwards compatibility
|
data/lib/rollbar/version.rb
CHANGED
data/spec/rollbar_spec.rb
CHANGED
@@ -154,6 +154,25 @@ describe Rollbar do
|
|
154
154
|
exception_data[:uuid].should_not be_nil
|
155
155
|
end
|
156
156
|
end
|
157
|
+
|
158
|
+
it 'should report exception objects with nonstandard backtraces' do
|
159
|
+
payload = nil
|
160
|
+
Rollbar.stub(:schedule_payload) do |*args|
|
161
|
+
payload = MultiJson.load(args[0])
|
162
|
+
end
|
163
|
+
|
164
|
+
class CustomException < StandardError
|
165
|
+
def backtrace
|
166
|
+
["custom backtrace line"]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
exception = CustomException.new("oops")
|
171
|
+
|
172
|
+
Rollbar.report_exception(exception)
|
173
|
+
|
174
|
+
payload["data"]["body"]["trace"]["frames"][0]["method"].should == "custom backtrace line"
|
175
|
+
end
|
157
176
|
end
|
158
177
|
|
159
178
|
context 'report_message' do
|
@@ -198,7 +217,8 @@ describe Rollbar do
|
|
198
217
|
c = { :b => b }
|
199
218
|
a[:c] = c
|
200
219
|
|
201
|
-
logger_mock.should_receive(:error).with(/\[Rollbar\]
|
220
|
+
logger_mock.should_receive(:error).with(/\[Rollbar\] Reporting internal error encountered while sending data to Rollbar./)
|
221
|
+
|
202
222
|
Rollbar.report_message("Test message with circular extra data", 'debug', a)
|
203
223
|
end
|
204
224
|
|
@@ -578,6 +598,30 @@ describe Rollbar do
|
|
578
598
|
end
|
579
599
|
end
|
580
600
|
|
601
|
+
context "report_internal_error" do
|
602
|
+
it "should not crash when given an exception object" do
|
603
|
+
begin
|
604
|
+
1 / 0
|
605
|
+
rescue => e
|
606
|
+
Rollbar.send(:report_internal_error, e)
|
607
|
+
end
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
context "send_failsafe" do
|
612
|
+
it "should not crash when given a message and exception" do
|
613
|
+
begin
|
614
|
+
1 / 0
|
615
|
+
rescue => e
|
616
|
+
Rollbar.send(:send_failsafe, "test failsafe", e)
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
it "should not crash when given all nils" do
|
621
|
+
Rollbar.send(:send_failsafe, nil, nil)
|
622
|
+
end
|
623
|
+
end
|
624
|
+
|
581
625
|
# configure with some basic params
|
582
626
|
def configure
|
583
627
|
Rollbar.reconfigure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rollbar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -288,4 +288,3 @@ test_files:
|
|
288
288
|
- spec/requests/home_spec.rb
|
289
289
|
- spec/rollbar_spec.rb
|
290
290
|
- spec/spec_helper.rb
|
291
|
-
has_rdoc:
|