rollbar 0.12.7 → 0.12.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49719df8414ae90f604bc7b140f82c6966d564b2
4
- data.tar.gz: 9e06c6c36b98bf02398bcdf4d6268f57fa01d390
3
+ metadata.gz: e51b5cb888086a9cd992d4c36cfc2fabd83b3635
4
+ data.tar.gz: 47c5991fb45cd69fe233e0dafc2d6c7c676c4196
5
5
  SHA512:
6
- metadata.gz: aeb6ea575bd2c8ba206936f76882cf304cffb1822be011f375c302f03b95f261558f792cea8aabcd79a799dce7c42d663b1034b1da39c2c7aee8fa9c03d4e375
7
- data.tar.gz: d2848c3268c75a73f1086ff8a8511b5eacb4d5649646fb7fbe1d9b7721efbed8932ae1ff21653e0b8b02aec78bc7e343c2b7d39c41d729adb373a1162062a9b5
6
+ metadata.gz: 894839031c7728ccd229396aa54d2125f33a0a067b1ce7fd09eb02f603db56a1a4f7f933679e3464bc8140d98c3ec9ee23236f25d8d803a621688b640f09494a
7
+ data.tar.gz: e64f0af2245fd337b668f1870c440e4c51211d31f301d05ab39bb14ec9eea51ff6bae5a1f0600cd984aef9a85386140b1684c2f909c5e6a7faa57e241e64ec07
data/CHANGELOG.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ **0.12.8**
4
+ - Added funcitonality to walk the payload and truncate strings to attempt to reduce size if the payload is too large (more than 32kb total)
5
+
3
6
  **0.12.7**
4
7
  - Fix error reporting errors when route controller or action is nil (bug introduced in 0.12.4)
5
8
 
6
9
  **0.12.6**
7
- - Added [#78](https://github.com/rollbar/rollbar-gem/pull/78), ability to ignore exceptions from specific persons
10
+ - Added [#78](https://github.com/rollbar/rollbar-gem/pull/78), added configuration option to ignore specific person exceptions
8
11
 
9
12
  **0.12.5**
10
13
  - Fixed SIGSEGV with the delayed_job plugin and Ruby 2.1.0
data/lib/rollbar.rb CHANGED
@@ -14,10 +14,13 @@ require 'rollbar/configuration'
14
14
  require 'rollbar/request_data_extractor'
15
15
  require 'rollbar/exception_reporter'
16
16
  require 'rollbar/active_record_extension' if defined?(ActiveRecord)
17
+ require 'rollbar/util'
17
18
 
18
19
  require 'rollbar/railtie' if defined?(Rails)
19
20
 
20
21
  module Rollbar
22
+ MAX_PAYLOAD_SIZE = 32 * 1042 #32kb
23
+
21
24
  class << self
22
25
  attr_writer :configuration
23
26
  attr_accessor :last_report
@@ -321,6 +324,10 @@ module Rollbar
321
324
  end
322
325
 
323
326
  def schedule_payload(payload)
327
+ if payload.nil?
328
+ return
329
+ end
330
+
324
331
  log_info '[Rollbar] Scheduling payload'
325
332
 
326
333
  if configuration.use_async
@@ -345,7 +352,28 @@ module Rollbar
345
352
  :access_token => configuration.access_token,
346
353
  :data => data
347
354
  }
348
- MultiJson.dump(payload)
355
+ result = MultiJson.dump(payload)
356
+
357
+ # Try to truncate strings in the payload a few times if the payload is too big
358
+ if result.bytesize > MAX_PAYLOAD_SIZE
359
+ thresholds = [1024, 512, 256]
360
+ thresholds.each_with_index do |threshold, i|
361
+ new_payload = payload.clone
362
+
363
+ truncate_payload(new_payload, threshold)
364
+
365
+ result = MultiJson.dump(new_payload)
366
+
367
+ if result.bytesize <= MAX_PAYLOAD_SIZE
368
+ break
369
+ elsif i == thresholds.length - 1
370
+ send_failsafe('Could not send payload due to it being too large after truncating attempts', nil)
371
+ return
372
+ end
373
+ end
374
+ end
375
+
376
+ result
349
377
  end
350
378
 
351
379
  def base_data(level = 'error')
@@ -380,7 +408,7 @@ module Rollbar
380
408
  unless config.custom_data_method.nil?
381
409
  data[:custom] = config.custom_data_method.call
382
410
  end
383
-
411
+
384
412
  data
385
413
  end
386
414
 
@@ -505,9 +533,19 @@ module Rollbar
505
533
  log_error "[Rollbar] Error sending failsafe : #{e}"
506
534
  end
507
535
  end
508
-
536
+
537
+ def truncate_payload(payload, byte_threshold)
538
+ truncator = Proc.new do |value|
539
+ if value.is_a?(String) and value.bytesize > byte_threshold
540
+ Rollbar::Util::truncate(value, byte_threshold)
541
+ else
542
+ value
543
+ end
544
+ end
545
+
546
+ Rollbar::Util::iterate_and_update(payload, truncator)
547
+ end
509
548
  end
510
-
511
549
  end
512
550
 
513
551
  # Setting Ratchetio as an alias to Rollbar for ratchetio-gem backwards compatibility
@@ -0,0 +1,35 @@
1
+ module Rollbar
2
+ module Util
3
+ def self.iterate_and_update(obj, block)
4
+ if obj.is_a?(Array)
5
+ for i in 0 ... obj.size
6
+ value = obj[i]
7
+
8
+ if value.is_a?(Hash) || value.is_a?(Array)
9
+ self.iterate_and_update(value, block)
10
+ else
11
+ obj[i] = block.call(value)
12
+ end
13
+ end
14
+ else
15
+ obj.each do |k, v|
16
+ if v.is_a?(Hash) || v.is_a?(Array)
17
+ self.iterate_and_update(v, block)
18
+ else
19
+ obj[k] = block.call(v)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def self.truncate(str, length)
26
+ ellipsis = '...'
27
+
28
+ if str.length <= length or str.length <= ellipsis.length
29
+ return str
30
+ end
31
+
32
+ str.unpack("U*").slice(0, length - ellipsis.length).pack("U*") + ellipsis
33
+ end
34
+ end
35
+ end
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = "0.12.7"
2
+ VERSION = "0.12.8"
3
3
  end
data/spec/rollbar_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'logger'
2
4
  require 'socket'
3
5
  require 'spec_helper'
@@ -603,11 +605,75 @@ describe Rollbar do
603
605
  end
604
606
 
605
607
  context 'build_payload' do
608
+ before(:each) do
609
+ configure
610
+ Rollbar.configure do |config|
611
+ config.logger = logger_mock
612
+ end
613
+ end
614
+
615
+ let(:logger_mock) { double("Rails.logger").as_null_object }
616
+
606
617
  it 'should build valid json' do
607
618
  json = Rollbar.send(:build_payload, {:foo => {:bar => "baz"}})
608
619
  hash = MultiJson.load(json)
609
620
  hash["data"]["foo"]["bar"].should == "baz"
610
621
  end
622
+
623
+ it 'should truncate large strings if the payload is too big' do
624
+ json = Rollbar.send(:build_payload, {:foo => {:bar => "baz"}, :large => 'a' * (64 * 1024), :small => 'b' * 1024})
625
+ hash = MultiJson.load(json)
626
+ hash["data"]["large"].should == '%s...' % ('a' * 1021)
627
+ hash["data"]["small"].should == 'b' * 1024
628
+ end
629
+
630
+ it 'should send a failsafe message if the payload cannot be reduced enough' do
631
+ logger_mock.should_receive(:error).with('[Rollbar] Sending failsafe response due to Could not send payload due to it being too large after truncating attempts.')
632
+ logger_mock.should_receive(:info).with('[Rollbar] Success')
633
+
634
+ orig_max = Rollbar::MAX_PAYLOAD_SIZE
635
+
636
+ Rollbar::MAX_PAYLOAD_SIZE = 1
637
+ Rollbar.report_exception(@exception)
638
+
639
+ Rollbar::MAX_PAYLOAD_SIZE = orig_max
640
+ end
641
+ end
642
+
643
+ context 'truncate_payload' do
644
+ it 'should truncate all nested strings in the payload' do
645
+ payload = {
646
+ :truncated => '1234567',
647
+ :not_truncated => '123456',
648
+ :hash => {
649
+ :inner_truncated => '123456789',
650
+ :inner_not_truncated => '567',
651
+ :array => ['12345678', '12', {:inner_inner => '123456789'}]
652
+ }
653
+ }
654
+
655
+ payload_copy = payload.clone
656
+ Rollbar.send(:truncate_payload, payload_copy, 6)
657
+
658
+ payload_copy[:truncated].should == '123...'
659
+ payload_copy[:not_truncated].should == '123456'
660
+ payload_copy[:hash][:inner_truncated].should == '123...'
661
+ payload_copy[:hash][:inner_not_truncated].should == '567'
662
+ payload_copy[:hash][:array].should == ['123...', '12', {:inner_inner => '123...'}]
663
+ end
664
+
665
+ it 'should truncate utf8 strings properly' do
666
+ payload = {
667
+ :truncated => 'Ŝǻмρļẻ śţяịņģ',
668
+ :not_truncated => '123456',
669
+ }
670
+
671
+ payload_copy = payload.clone
672
+ Rollbar.send(:truncate_payload, payload_copy, 6)
673
+
674
+ payload_copy[:truncated].should == "Ŝǻм..."
675
+ payload_copy[:not_truncated].should == '123456'
676
+ end
611
677
  end
612
678
 
613
679
  context 'base_data' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.7
4
+ version: 0.12.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Rue
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -167,6 +167,7 @@ files:
167
167
  - lib/rollbar/rake_tasks.rb
168
168
  - lib/rollbar/request_data_extractor.rb
169
169
  - lib/rollbar/sidekiq.rb
170
+ - lib/rollbar/util.rb
170
171
  - lib/rollbar/version.rb
171
172
  - rollbar.gemspec
172
173
  - spec/controllers/home_controller_spec.rb