rollbar 1.0.0 → 1.0.1

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: 3f2c782eb71538b4fa602e2e56c56233559858f7
4
- data.tar.gz: 6ad6c0a6b66963dc0b0a2bdb0705df9d95e4f468
3
+ metadata.gz: 26233ef7ffa02228b4777c5ef26655f9208541e9
4
+ data.tar.gz: 14feffe767b5d9764afc4508ed139a9d2394ada3
5
5
  SHA512:
6
- metadata.gz: fddd828f6ff42f93a0211e4967baf4a99ff1c93f1b5c1ee1a231004627b80c5b18dfbf6684d94a141144e29bebd17e5d9e6d977844506fb62cd7524272e29ebe
7
- data.tar.gz: f6820508de41ddc3fcb9ff89bab83da096a6b778d97bdca10297982561f139d6f1c7591d120bb9165a3bcc3601d7ca5f17c89a137cb49f114b00c8c01273f77c
6
+ metadata.gz: c38f8b6ea8dbdafe38b68cbc5b1902b21e7a55f29ebc154fe23d4a9a2a50d4bba01e623b917f4ba6e3ee17611cbb4d55b07035e40d83ae35eaa90b7ed4fab326
7
+ data.tar.gz: 08a2f63d80dd45c48eb297e6cfbfc0f551004ad7c4280b2b6a71bb79b3887c814910307c83b742f5ad420586e795f95cf52e4bf7f1a00561e54d3cb4ef671c7e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ **1.0.1**
4
+ - Use the payload's access token for the X-Rollbar-Access-Token header, instead of the configured access token. Fixes an issue where payloads would be reported into the wrong project when sent via Resque. See [#128](https://github.com/rollbar/rollbar-gem/pull/128). Thanks to [@jondeandres](https://github.com/jondeandres) for the fix.
5
+
3
6
  **1.0.0**
4
7
  - Clean up some unused requires
5
8
  - Strip out invalid UTF-8 characters from payload keys/values, fixes [#85](https://github.com/rollbar/rollbar-gem/issues/85)
@@ -94,7 +97,7 @@
94
97
  - Fix syntax error in `config.use_sidekiq` usage example
95
98
 
96
99
  **0.12.0**
97
- - Added [#73](https://github.com/rollbar/rollbar-gem/pull/73), enhanced Sidekiq and SuckerPunch configuration. NOTE: The old `Rollbar::Configuration#use_sidekiq=` and `Rollbar::Configuration#use_sucker_punch=` methods are now depricated, see the docs for updated usage information.
100
+ - Added [#73](https://github.com/rollbar/rollbar-gem/pull/73), enhanced Sidekiq and SuckerPunch configuration. NOTE: The old `Rollbar::Configuration#use_sidekiq=` and `Rollbar::Configuration#use_sucker_punch=` methods are now deprecated, see the docs for updated usage information.
98
101
 
99
102
  **0.11.8**
100
103
  - Make sure the person method exists for the controller before trying to extract person data
data/README.md CHANGED
@@ -9,7 +9,7 @@ Ruby gem for reporting exceptions, errors, and log messages to [Rollbar](https:/
9
9
 
10
10
  Add this line to your application's Gemfile:
11
11
 
12
- gem 'rollbar'
12
+ gem 'rollbar', '~> 1.0.0'
13
13
 
14
14
  And then execute:
15
15
 
data/lib/rollbar.rb CHANGED
@@ -374,7 +374,10 @@ module Rollbar
374
374
  end
375
375
 
376
376
  def send_payload_using_eventmachine(payload)
377
- req = EventMachine::HttpRequest.new(configuration.endpoint).post(:body => payload)
377
+ body = dump_payload(payload)
378
+ headers = { 'X-Rollbar-Access-Token' => payload['access_token'] }
379
+ req = EventMachine::HttpRequest.new(configuration.endpoint).post(:body => body, :head => headers)
380
+
378
381
  req.callback do
379
382
  if req.response_header.status == 200
380
383
  log_info '[Rollbar] Success'
@@ -391,11 +394,14 @@ module Rollbar
391
394
 
392
395
  def send_payload(payload)
393
396
  log_info '[Rollbar] Sending payload'
397
+ payload = MultiJson.load(payload) if payload.is_a?(String)
394
398
 
395
399
  if configuration.use_eventmachine
396
400
  send_payload_using_eventmachine(payload)
397
401
  return
398
402
  end
403
+
404
+ body = dump_payload(payload)
399
405
  uri = URI.parse(configuration.endpoint)
400
406
  http = Net::HTTP.new(uri.host, uri.port)
401
407
  http.read_timeout = configuration.request_timeout
@@ -406,8 +412,8 @@ module Rollbar
406
412
  end
407
413
 
408
414
  request = Net::HTTP::Post.new(uri.request_uri)
409
- request.body = payload
410
- request.add_field('X-Rollbar-Access-Token', configuration.access_token)
415
+ request.body = body
416
+ request.add_field('X-Rollbar-Access-Token', payload['access_token'])
411
417
  response = http.request(request)
412
418
 
413
419
  if response.code == '200'
@@ -444,12 +450,15 @@ module Rollbar
444
450
 
445
451
  def build_payload(data)
446
452
  payload = {
447
- :access_token => configuration.access_token,
448
- :data => data
453
+ 'access_token' => configuration.access_token,
454
+ 'data' => data
449
455
  }
450
-
456
+
451
457
  enforce_valid_utf8(payload)
452
-
458
+ payload
459
+ end
460
+
461
+ def dump_payload(payload)
453
462
  result = MultiJson.dump(payload)
454
463
 
455
464
  # Try to truncate strings in the payload a few times if the payload is too big
@@ -589,18 +598,16 @@ module Rollbar
589
598
  config = configuration
590
599
  environment = config.environment
591
600
 
592
- failsafe_payload = <<-eos
593
- {"access_token": "#{config.access_token}",
594
- "data": {
595
- "level": "error",
596
- "environment": "#{config.environment}",
597
- "body": { "message": { "body": "Failsafe from rollbar-gem: #{message}" } },
598
- "notifier": { "name": "rollbar-gem", "version": "#{VERSION}" },
599
- "internal": true,
600
- "failsafe": true
601
- }
601
+ failsafe_data = {
602
+ :level => 'error',
603
+ :environment => "#{environment}",
604
+ :body => { :message => { :body => "Failsafe from rollbar-gem: #{message}" } },
605
+ :notifier => { :name => 'rollbar-gem', :version => "#{VERSION}" },
606
+ :internal => true,
607
+ :failsafe => true
602
608
  }
603
- eos
609
+
610
+ failsafe_payload = build_payload(failsafe_data)
604
611
 
605
612
  begin
606
613
  schedule_payload(failsafe_payload)
@@ -608,7 +615,7 @@ module Rollbar
608
615
  log_error "[Rollbar] Error sending failsafe : #{e}"
609
616
  end
610
617
  end
611
-
618
+
612
619
  def enforce_valid_utf8(payload)
613
620
  normalizer = Proc.new do |value|
614
621
  if value.is_a?(String)
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
data/rollbar.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
  require File.expand_path('../lib/rollbar/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Brian Rue"]
6
- gem.email = ["brian@rollbar.com"]
5
+ gem.authors = ["Rollbar, Inc."]
6
+ gem.email = ["support@rollbar.com"]
7
7
  gem.description = %q{Rails plugin to catch and send exceptions to Rollbar}
8
8
  gem.summary = %q{Reports exceptions to Rollbar}
9
9
  gem.homepage = "https://github.com/rollbar/rollbar-gem"
@@ -6,7 +6,7 @@ describe HomeController do
6
6
  before(:each) do
7
7
  reset_configuration
8
8
  Rollbar.configure do |config|
9
- config.access_token = 'aaaabbbbccccddddeeeeffff00001111'
9
+ config.access_token = 'bfec94a1ede64984b862880224edd0ed'
10
10
  config.environment = ::Rails.env
11
11
  config.root = ::Rails.root
12
12
  config.framework = "Rails: #{::Rails::VERSION::STRING}"
data/spec/rollbar_spec.rb CHANGED
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  describe Rollbar do
15
15
 
16
- context 'report_exception' do
16
+ describe '.report_exception' do
17
17
  before(:each) do
18
18
  configure
19
19
  Rollbar.configure do |config|
@@ -208,12 +208,12 @@ describe Rollbar do
208
208
  it 'should report exception objects with no backtrace' do
209
209
  payload = nil
210
210
  Rollbar.stub(:schedule_payload) do |*args|
211
- payload = MultiJson.load(args[0])
211
+ payload = args[0]
212
212
  end
213
213
  Rollbar.report_exception(StandardError.new("oops"))
214
- payload["data"]["body"]["trace"]["frames"].should == []
215
- payload["data"]["body"]["trace"]["exception"]["class"].should == "StandardError"
216
- payload["data"]["body"]["trace"]["exception"]["message"].should == "oops"
214
+ payload["data"][:body][:trace][:frames].should == []
215
+ payload["data"][:body][:trace][:exception][:class].should == "StandardError"
216
+ payload["data"][:body][:trace][:exception][:message].should == "oops"
217
217
  end
218
218
 
219
219
  it 'should return the exception data with a uuid, on platforms with SecureRandom' do
@@ -227,7 +227,7 @@ describe Rollbar do
227
227
  it 'should report exception objects with nonstandard backtraces' do
228
228
  payload = nil
229
229
  Rollbar.stub(:schedule_payload) do |*args|
230
- payload = MultiJson.load(args[0])
230
+ payload = args[0]
231
231
  end
232
232
 
233
233
  class CustomException < StandardError
@@ -240,22 +240,22 @@ describe Rollbar do
240
240
 
241
241
  Rollbar.report_exception(exception)
242
242
 
243
- payload["data"]["body"]["trace"]["frames"][0]["method"].should == "custom backtrace line"
243
+ payload["data"][:body][:trace][:frames][0][:method].should == "custom backtrace line"
244
244
  end
245
245
 
246
246
  it 'should report exceptions with a custom level' do
247
247
  payload = nil
248
248
  Rollbar.stub(:schedule_payload) do |*args|
249
- payload = MultiJson.load(args[0])
249
+ payload = args[0]
250
250
  end
251
251
 
252
252
  Rollbar.report_exception(@exception)
253
253
 
254
- payload["data"]["level"].should == 'error'
254
+ payload["data"][:level].should == 'error'
255
255
 
256
256
  Rollbar.report_exception(@exception, nil, nil, 'debug')
257
257
 
258
- payload["data"]["level"].should == 'debug'
258
+ payload["data"][:level].should == 'debug'
259
259
  end
260
260
  end
261
261
 
@@ -475,6 +475,31 @@ describe Rollbar do
475
475
  end
476
476
  end
477
477
 
478
+ # We should be able to send String payloads, generated
479
+ # by a previous version of the gem. This can happend just
480
+ # after a deploy with an gem upgrade.
481
+ context 'with a payload generated as String' do
482
+ let(:async_handler) do
483
+ proc do |payload|
484
+ # simulate previous gem version
485
+ string_payload = MultiJson.dump(payload)
486
+
487
+ Rollbar.process_payload(string_payload)
488
+ end
489
+ end
490
+
491
+ before do
492
+ Rollbar.configuration.stub(:use_async).and_return(true)
493
+ Rollbar.configuration.stub(:async_handler).and_return(async_handler)
494
+ end
495
+
496
+ it 'sends a payload generated as String, not as a Hash' do
497
+ logger_mock.should_receive(:info).with('[Rollbar] Success')
498
+
499
+ Rollbar.report_exception(@exception)
500
+ end
501
+ end
502
+
478
503
  describe "#use_sucker_punch", :if => defined?(SuckerPunch) do
479
504
  it "should send the payload to sucker_punch delayer" do
480
505
  logger_mock.should_receive(:info).with('[Rollbar] Scheduling payload')
@@ -662,13 +687,13 @@ describe Rollbar do
662
687
  let(:logger_mock) { double("Rails.logger").as_null_object }
663
688
 
664
689
  it 'should build valid json' do
665
- json = Rollbar.send(:build_payload, {:foo => {:bar => "baz"}})
666
- hash = MultiJson.load(json)
667
- hash["data"]["foo"]["bar"].should == "baz"
690
+ data = { :foo => { :bar => 'baz'}}
691
+ payload = Rollbar.send(:build_payload, data)
692
+ payload["data"][:foo][:bar].should == "baz"
668
693
  end
669
-
694
+
670
695
  it 'should strip out invalid utf-8' do
671
- json = Rollbar.send(:build_payload, {
696
+ payload = Rollbar.send(:build_payload, {
672
697
  :good_key => "\255bad value",
673
698
  "bad\255 key" => "good value",
674
699
  "bad key 2\255" => "bad \255value",
@@ -676,18 +701,20 @@ describe Rollbar do
676
701
  "bad array \255key" => ["bad\255 array element", "good array element"]
677
702
  }
678
703
  })
679
-
680
- hash = MultiJson.load(json)
681
- hash["data"]["good_key"].should == 'bad value'
682
- hash["data"]["bad key"].should == 'good value'
683
- hash["data"]["bad key 2"].should == 'bad value'
684
- hash["data"]["hash"].should == {
704
+
705
+ payload["data"][:good_key].should == 'bad value'
706
+ payload["data"]["bad key"].should == 'good value'
707
+ payload["data"]["bad key 2"].should == 'bad value'
708
+ payload["data"][:hash].should == {
685
709
  "bad array key" => ["bad array element", "good array element"]
686
710
  }
687
711
  end
688
712
 
689
713
  it 'should truncate large strings if the payload is too big' do
690
- json = Rollbar.send(:build_payload, {:foo => {:bar => "baz"}, :large => 'a' * (128 * 1024), :small => 'b' * 1024})
714
+ data = {:foo => {:bar => "baz"}, :large => 'a' * (128 * 1024), :small => 'b' * 1024}
715
+ payload = Rollbar.send(:build_payload, data)
716
+ json = Rollbar.send(:dump_payload, payload)
717
+
691
718
  hash = MultiJson.load(json)
692
719
  hash["data"]["large"].should == '%s...' % ('a' * 1021)
693
720
  hash["data"]["small"].should == 'b' * 1024
@@ -698,14 +725,18 @@ describe Rollbar do
698
725
  logger_mock.should_receive(:info).with('[Rollbar] Success')
699
726
 
700
727
  orig_max = Rollbar::MAX_PAYLOAD_SIZE
701
-
702
728
  Rollbar::MAX_PAYLOAD_SIZE = 1
703
- Rollbar.report_exception(@exception)
729
+ orig_send_failsafe = Rollbar.method(:send_failsafe)
704
730
 
705
- Rollbar::MAX_PAYLOAD_SIZE = orig_max
731
+ Rollbar.stub(:send_failsafe) do |message, exception|
732
+ Rollbar::MAX_PAYLOAD_SIZE = orig_max
733
+ orig_send_failsafe.call(message, exception)
734
+ end
735
+
736
+ Rollbar.report_exception(@exception)
706
737
  end
707
738
  end
708
-
739
+
709
740
  context 'enforce_valid_utf8' do
710
741
  it 'should replace invalid utf8 values' do
711
742
  payload = {
@@ -716,7 +747,7 @@ describe Rollbar do
716
747
  :inner_bad_value => "\255\255bad value 3",
717
748
  "inner \255bad key" => 'inner good value',
718
749
  "bad array key\255" => [
719
- 'good array value 1',
750
+ 'good array value 1',
720
751
  "bad\255 array value 1\255",
721
752
  {
722
753
  :inner_inner_bad => "bad inner \255inner value"
@@ -727,7 +758,7 @@ describe Rollbar do
727
758
 
728
759
  payload_copy = payload.clone
729
760
  Rollbar.send(:enforce_valid_utf8, payload_copy)
730
-
761
+
731
762
  payload_copy[:bad_value].should == "bad value 1"
732
763
  payload_copy[:bad_value_2].should == "bad value 2"
733
764
  payload_copy["bad key"].should == "good value"
@@ -735,8 +766,8 @@ describe Rollbar do
735
766
  payload_copy[:hash][:inner_bad_value].should == "bad value 3"
736
767
  payload_copy[:hash]["inner bad key"].should == 'inner good value'
737
768
  payload_copy[:hash]["bad array key"].should == [
738
- 'good array value 1',
739
- 'bad array value 1',
769
+ 'good array value 1',
770
+ 'bad array value 1',
740
771
  {
741
772
  :inner_inner_bad => 'bad inner inner value'
742
773
  }
@@ -881,7 +912,7 @@ describe Rollbar do
881
912
 
882
913
  gem_paths = gems.map{|gem| Gem::Specification.find_all_by_name(gem).map(&:gem_dir) }.flatten.compact.uniq
883
914
  gem_paths.length.should > 1
884
-
915
+
885
916
  gem_paths.any?{|path| path.include? 'rollbar-gem'}.should == true
886
917
  gem_paths.any?{|path| path.include? 'rspec-rails'}.should == true
887
918
 
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.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - Brian Rue
7
+ - Rollbar, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -124,7 +124,7 @@ dependencies:
124
124
  version: 0.2.7
125
125
  description: Rails plugin to catch and send exceptions to Rollbar
126
126
  email:
127
- - brian@rollbar.com
127
+ - support@rollbar.com
128
128
  executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []