rollbar 1.2.10 → 1.2.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+ require 'rollbar/truncation/frames_strategy'
3
+
4
+ describe Rollbar::Truncation::FramesStrategy do
5
+ def expand_frames(frames)
6
+ frames * (1 + 300 / frames.count)
7
+ end
8
+
9
+ describe '.call', :fixture => :payload do
10
+ context 'with trace key' do
11
+ let(:payload_fixture) { 'payloads/sample.trace.json' }
12
+ let(:frames) { payload['data'][:body][:trace][:frames].clone }
13
+
14
+ before do
15
+ payload['data'][:body][:trace][:frames] = expand_frames(frames)
16
+ end
17
+
18
+ it 'returns a new payload with 300 frames' do
19
+ result = symbolize_recursive(MultiJson.load(described_class.call(payload)))
20
+
21
+ new_frames = result[:data][:body][:trace][:frames]
22
+
23
+ expect(new_frames.count).to be_eql(300)
24
+ expect(new_frames.first).to be_eql(frames.first)
25
+ expect(new_frames.last).to be_eql(frames.last)
26
+ end
27
+ end
28
+
29
+ context 'with trace_chain key' do
30
+ let(:payload_fixture) { 'payloads/sample.trace_chain.json' }
31
+
32
+ let(:frames1) { payload['data'][:body][:trace_chain][0][:frames].clone }
33
+ let(:frames2) { payload['data'][:body][:trace_chain][1][:frames].clone }
34
+
35
+ before do
36
+ payload['data'][:body][:trace_chain][0][:frames] = expand_frames(frames1)
37
+ payload['data'][:body][:trace_chain][1][:frames] = expand_frames(frames2)
38
+ end
39
+
40
+ it 'returns a new payload with 300 frames for each chain item' do
41
+ result = symbolize_recursive(MultiJson.load(described_class.call(payload)))
42
+
43
+ new_frames1 = result[:data][:body][:trace_chain][0][:frames]
44
+ new_frames2 = result[:data][:body][:trace_chain][1][:frames]
45
+
46
+ expect(new_frames1.count).to be_eql(300)
47
+ expect(new_frames1.first).to be_eql(frames1.first)
48
+ expect(new_frames1.last).to be_eql(frames1.last)
49
+
50
+ expect(new_frames2.count).to be_eql(300)
51
+ expect(new_frames2.first).to be_eql(frames2.first)
52
+ expect(new_frames2.last).to be_eql(frames2.last)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'rollbar/truncation/frames_strategy'
3
+
4
+ describe Rollbar::Truncation::MinBodyStrategy do
5
+ describe '.call', :fixture => :payload do
6
+ let(:message) { 'a' * 1_000 }
7
+
8
+ context 'with trace key ' do
9
+ let(:payload_fixture) { 'payloads/sample.trace.json' }
10
+ let!(:frames) { payload['data'][:body][:trace][:frames].clone }
11
+
12
+ before do
13
+ payload['data'][:body][:trace][:exception][:message] = message
14
+ end
15
+
16
+ it 'truncates the exception message and frames array' do
17
+ result = symbolize_recursive(MultiJson.load(described_class.call(payload)))
18
+
19
+ trace = result[:data][:body][:trace]
20
+ expect(trace[:frames]).to have(2).items
21
+ expect(trace[:exception][:message]).to be_eql('a' * 255)
22
+ end
23
+ end
24
+
25
+ context 'with trace_chain key ' do
26
+ let(:payload_fixture) { 'payloads/sample.trace_chain.json' }
27
+ let!(:frames1) { payload['data'][:body][:trace_chain][0][:frames].clone }
28
+ let!(:frames2) { payload['data'][:body][:trace_chain][1][:frames].clone }
29
+
30
+ before do
31
+ payload['data'][:body][:trace_chain][0][:exception][:message] = message
32
+ payload['data'][:body][:trace_chain][1][:exception][:message] = message
33
+ end
34
+
35
+ it 'truncates the exception message and frames array' do
36
+ result = symbolize_recursive(MultiJson.load(described_class.call(payload)))
37
+
38
+ traces = result[:data][:body][:trace_chain]
39
+ expect(traces[0][:frames]).to have(2).items
40
+ expect(traces[0][:exception][:message]).to be_eql('a' * 255)
41
+
42
+ expect(traces[1][:frames]).to have(2).items
43
+ expect(traces[1][:exception][:message]).to be_eql('a' * 255)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,89 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+ require 'rollbar/truncation/frames_strategy'
5
+
6
+ describe Rollbar::Truncation::StringsStrategy do
7
+ describe '.call' do
8
+ let(:long_message) { 'a' * 2000 }
9
+ let(:payload) do
10
+ {
11
+ :truncated => long_message,
12
+ :not_truncated => '123456',
13
+ :hash => {
14
+ :inner_truncated => long_message,
15
+ :inner_not_truncated => '567',
16
+ :array => ['12345678', '12', { :inner_inner => long_message }]
17
+ }
18
+ }
19
+ end
20
+
21
+ it 'should truncate all nested strings in the payload' do
22
+ result = symbolize_recursive(MultiJson.load(described_class.call(payload)))
23
+
24
+ expect(result[:truncated].size).to be_eql(1024)
25
+ expect(result[:hash][:inner_truncated].size).to be_eql(1024)
26
+ expect(result[:hash][:array][2][:inner_inner].size).to be_eql(1024)
27
+ end
28
+
29
+ context 'with utf8 strings' do
30
+ let(:long_message) { 'Ŝǻмρļẻ śţяịņģ' + 'a' * 2000 }
31
+ let(:payload) do
32
+ {
33
+ :truncated => long_message,
34
+ :not_truncated => '123456',
35
+ }
36
+ end
37
+
38
+ it 'should truncate utf8 strings properly' do
39
+ result = symbolize_recursive(MultiJson.load(described_class.call(payload)))
40
+ expect(result[:truncated]).to match(/^Ŝǻмρļẻ śţяịņģa*\.{3}/)
41
+ end
42
+ end
43
+
44
+ context 'when first threshold is not enough' do
45
+ let(:payload) do
46
+ 129.times.to_enum.reduce({}) do |hash, i|
47
+ hash[i.to_s] = 'a' * 1024
48
+ hash
49
+ end
50
+ end
51
+
52
+ it 'truncates to 512 size strings' do
53
+ result = MultiJson.load(described_class.call(payload))
54
+
55
+ expect(result['0'].size).to be_eql(512)
56
+ end
57
+ end
58
+
59
+ context 'when second threshold is still not enough' do
60
+ let(:payload) do
61
+ 257.times.to_enum.reduce({}) do |hash, i|
62
+ hash[i.to_s] = 'a' * 1024
63
+ hash
64
+ end
65
+ end
66
+
67
+ it 'truncates to 256 size strings, the third threshold' do
68
+ result = MultiJson.load(described_class.call(payload))
69
+
70
+ expect(result['0'].size).to be_eql(256)
71
+ end
72
+ end
73
+
74
+ context 'when third threshold is still not enough' do
75
+ let(:payload) do
76
+ 1024.times.to_enum.reduce({}) do |hash, i|
77
+ hash[i.to_s] = 'a' * 1024
78
+ hash
79
+ end
80
+ end
81
+
82
+ it 'just return the value for third threshold' do
83
+ result = MultiJson.load(described_class.call(payload))
84
+
85
+ expect(result['0'].size).to be_eql(256)
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'rollbar/truncation'
3
+
4
+ describe Rollbar::Truncation do
5
+ describe '.truncate' do
6
+ let(:payload) { {} }
7
+
8
+ context 'if truncation is not needed' do
9
+ it 'only calls RawStrategy is truncation is not needed' do
10
+ allow(described_class).to receive(:truncate?).and_return(false)
11
+ expect(Rollbar::Truncation::RawStrategy).to receive(:call).with(payload)
12
+
13
+ Rollbar::Truncation.truncate(payload)
14
+ end
15
+ end
16
+
17
+ context 'if truncation is needed' do
18
+ it 'calls the next strategy, FramesStrategy' do
19
+ allow(described_class).to receive(:truncate?).and_return(true, false)
20
+ expect(Rollbar::Truncation::RawStrategy).to receive(:call).with(payload)
21
+ expect(Rollbar::Truncation::FramesStrategy).to receive(:call).with(payload)
22
+
23
+ Rollbar::Truncation.truncate(payload)
24
+ end
25
+ end
26
+ end
27
+ end
data/spec/rollbar_spec.rb CHANGED
@@ -13,6 +13,23 @@ end
13
13
 
14
14
  describe Rollbar do
15
15
  let(:notifier) { Rollbar.notifier }
16
+
17
+ context 'when notifier has been used before configure it' do
18
+ before do
19
+ Rollbar.unconfigure
20
+ Rollbar.reset_notifier!
21
+ end
22
+
23
+ it 'is finally reset' do
24
+ Rollbar.log_debug('Testing notifier')
25
+ expect(Rollbar.error('error message')).to be_eql('disabled')
26
+
27
+ reconfigure_notifier
28
+
29
+ expect(Rollbar.error('error message')).not_to be_eql('disabled')
30
+ end
31
+ end
32
+
16
33
  context 'Notifier' do
17
34
  context 'log' do
18
35
  let(:exception) do
@@ -642,42 +659,6 @@ describe Rollbar do
642
659
  body[:message][:extra][:hash].should == {:inner_key => 'inner_value'}
643
660
  end
644
661
  end
645
-
646
- context 'truncate_payload' do
647
- it 'should truncate all nested strings in the payload' do
648
- payload = {
649
- :truncated => '1234567',
650
- :not_truncated => '123456',
651
- :hash => {
652
- :inner_truncated => '123456789',
653
- :inner_not_truncated => '567',
654
- :array => ['12345678', '12', {:inner_inner => '123456789'}]
655
- }
656
- }
657
-
658
- payload_copy = payload.clone
659
- notifier.send(:truncate_payload, payload_copy, 6)
660
-
661
- payload_copy[:truncated].should == '123...'
662
- payload_copy[:not_truncated].should == '123456'
663
- payload_copy[:hash][:inner_truncated].should == '123...'
664
- payload_copy[:hash][:inner_not_truncated].should == '567'
665
- payload_copy[:hash][:array].should == ['123...', '12', {:inner_inner => '123...'}]
666
- end
667
-
668
- it 'should truncate utf8 strings properly' do
669
- payload = {
670
- :truncated => 'Ŝǻмρļẻ śţяịņģ',
671
- :not_truncated => '123456',
672
- }
673
-
674
- payload_copy = payload.clone
675
- notifier.send(:truncate_payload, payload_copy, 6)
676
-
677
- payload_copy[:truncated].should == "Ŝǻм..."
678
- payload_copy[:not_truncated].should == '123456'
679
- end
680
- end
681
662
  end
682
663
 
683
664
  context 'reporting' do
data/spec/spec_helper.rb CHANGED
@@ -16,6 +16,7 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
16
16
 
17
17
  RSpec.configure do |config|
18
18
  config.include(NotifierHelpers)
19
+ config.include(FixtureHelpers)
19
20
 
20
21
  config.color_enabled = true
21
22
  config.formatter = 'documentation'
@@ -38,7 +39,7 @@ RSpec.configure do |config|
38
39
  end
39
40
  config.backtrace_exclusion_patterns = [/gems\/rspec-.*/]
40
41
 
41
- if ENV['SKIP_DUMMY_ROLLBAR']
42
+ if ENV['SKIP_DUMMY_ROLLBAR'] == 'true'
42
43
  config.filter_run(:skip_dummy_rollbar => true)
43
44
  else
44
45
  config.filter_run_excluding(:skip_dummy_rollbar => true)
@@ -0,0 +1,27 @@
1
+ module FixtureHelpers
2
+ def fixture_file(relative_path)
3
+ root = File.expand_path('../../fixtures', __FILE__)
4
+ File.join(root, relative_path)
5
+ end
6
+
7
+ def load_payload_fixture(relative_path)
8
+ MultiJson.load(File.read(fixture_file(relative_path)))
9
+ end
10
+
11
+ def symbolize_recursive(hash)
12
+ {}.tap do |h|
13
+ hash.each { |key, value| h[key.to_sym] = map_value(value) }
14
+ end
15
+ end
16
+
17
+ def map_value(thing)
18
+ case thing
19
+ when Hash
20
+ symbolize_recursive(thing)
21
+ when Array
22
+ thing.map { |v| map_value(v) }
23
+ else
24
+ thing
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,12 @@
1
1
  shared_context 'reconfigure notifier', :reconfigure_notifier => true do
2
2
  before { reconfigure_notifier }
3
3
  end
4
+
5
+ shared_context 'payload from fixture', :fixture => :payload do
6
+ let(:payload) do
7
+ {
8
+ 'data' => symbolize_recursive(load_payload_fixture(payload_fixture)),
9
+ 'access_token' => 'the-token'
10
+ }
11
+ end
12
+ end
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: 1.2.10
4
+ version: 1.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rollbar, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-24 00:00:00.000000000 Z
11
+ date: 2014-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -219,6 +219,12 @@ files:
219
219
  - lib/rollbar/request_data_extractor.rb
220
220
  - lib/rollbar/sidekiq.rb
221
221
  - lib/rollbar/tasks/rollbar.cap
222
+ - lib/rollbar/truncation.rb
223
+ - lib/rollbar/truncation/frames_strategy.rb
224
+ - lib/rollbar/truncation/min_body_strategy.rb
225
+ - lib/rollbar/truncation/mixin.rb
226
+ - lib/rollbar/truncation/raw_strategy.rb
227
+ - lib/rollbar/truncation/strings_strategy.rb
222
228
  - lib/rollbar/util.rb
223
229
  - lib/rollbar/version.rb
224
230
  - rollbar.gemspec
@@ -275,6 +281,8 @@ files:
275
281
  - spec/dummyapp/public/500.html
276
282
  - spec/dummyapp/public/favicon.ico
277
283
  - spec/dummyapp/script/rails
284
+ - spec/fixtures/payloads/sample.trace.json
285
+ - spec/fixtures/payloads/sample.trace_chain.json
278
286
  - spec/generators/rollbar/rollbar_generator_spec.rb
279
287
  - spec/requests/home_spec.rb
280
288
  - spec/rollbar/configuration_spec.rb
@@ -285,10 +293,15 @@ files:
285
293
  - spec/rollbar/logger_proxy_spec.rb
286
294
  - spec/rollbar/middleware/rack/builder_spec.rb
287
295
  - spec/rollbar/middleware/sinatra_spec.rb
296
+ - spec/rollbar/truncation/frames_strategy_spec.rb
297
+ - spec/rollbar/truncation/min_body_strategy_spec.rb
298
+ - spec/rollbar/truncation/strings_strategy_spec.rb
299
+ - spec/rollbar/truncation_spec.rb
288
300
  - spec/rollbar_bc_spec.rb
289
301
  - spec/rollbar_spec.rb
290
302
  - spec/spec_helper.rb
291
303
  - spec/support/cause_exception.rb
304
+ - spec/support/fixture_helpers.rb
292
305
  - spec/support/notifier_helpers.rb
293
306
  - spec/support/shared_contexts.rb
294
307
  homepage: https://github.com/rollbar/rollbar-gem
@@ -369,6 +382,8 @@ test_files:
369
382
  - spec/dummyapp/public/500.html
370
383
  - spec/dummyapp/public/favicon.ico
371
384
  - spec/dummyapp/script/rails
385
+ - spec/fixtures/payloads/sample.trace.json
386
+ - spec/fixtures/payloads/sample.trace_chain.json
372
387
  - spec/generators/rollbar/rollbar_generator_spec.rb
373
388
  - spec/requests/home_spec.rb
374
389
  - spec/rollbar/configuration_spec.rb
@@ -379,9 +394,14 @@ test_files:
379
394
  - spec/rollbar/logger_proxy_spec.rb
380
395
  - spec/rollbar/middleware/rack/builder_spec.rb
381
396
  - spec/rollbar/middleware/sinatra_spec.rb
397
+ - spec/rollbar/truncation/frames_strategy_spec.rb
398
+ - spec/rollbar/truncation/min_body_strategy_spec.rb
399
+ - spec/rollbar/truncation/strings_strategy_spec.rb
400
+ - spec/rollbar/truncation_spec.rb
382
401
  - spec/rollbar_bc_spec.rb
383
402
  - spec/rollbar_spec.rb
384
403
  - spec/spec_helper.rb
385
404
  - spec/support/cause_exception.rb
405
+ - spec/support/fixture_helpers.rb
386
406
  - spec/support/notifier_helpers.rb
387
407
  - spec/support/shared_contexts.rb