airbrake-ruby 1.0.4 → 1.1.0

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: 1d15481adc9973cf21c5302ab3cd3dbb365d4891
4
- data.tar.gz: 94b9535ca5be9f4a28a75a24548516755cf5945e
3
+ metadata.gz: feeb44b47c5b58cdf1f478065f84640af9102ab9
4
+ data.tar.gz: 2319d39125a79fb075a3a629fa3dc8c927e95dc2
5
5
  SHA512:
6
- metadata.gz: 2426fc74599daab97fe712b40b1f9d8a3a899ef721cd28091e86aa88a91c8bbd16e727452ca70a564f80863b4c32d95cf428f78f4db5fc376fc389bb589fd5dc
7
- data.tar.gz: f04c48e0820d3b96c61618c08403845ca4730acc08eb4e68f8668cc52ce6365b28d35d0b4ab5293a22d5290e2863c1d4f100d57bc81fe14162f9c4fce67e9458
6
+ metadata.gz: 78028e33ffe3b0929fc6f5e26b18933d39df58edade9cbf45bd1ca9025d2121201cbf8fa114f9c9ff5614336d2521012d44d9b05dfadb0af08d9710ee40b3bcd
7
+ data.tar.gz: 14e8924670cac95429572ca814d61421459797059a357a39cf23b18241bf8cb9ff084bbb5b6357441e4f85ae5e11cbff2aa18e24668ec03bc493cb45131dbe8a
@@ -24,6 +24,8 @@ module Airbrake
24
24
  # library
25
25
  # @return [nil]
26
26
  def send(notice)
27
+ return will_not_deliver(notice) if @unsent.size >= @unsent.max
28
+
27
29
  @unsent << notice
28
30
  nil
29
31
  end
@@ -99,5 +101,17 @@ module Airbrake
99
101
  end
100
102
  end
101
103
  end
104
+
105
+ def will_not_deliver(notice)
106
+ backtrace = notice[:errors][0][:backtrace].map do |line|
107
+ "#{line[:file]}:#{line[:line]} in `#{line[:function]}'"
108
+ end
109
+ @config.logger.error(
110
+ "#{LOG_LABEL} AsyncSender has reached its capacity of " \
111
+ "#{@unsent.max} and the following notice will not be delivered " \
112
+ "Error: #{notice[:errors][0][:type]} - #{notice[:errors][0][:message]}\n" \
113
+ "Backtrace: \n" + backtrace.join("\n"))
114
+ nil
115
+ end
102
116
  end
103
117
  end
@@ -53,6 +53,10 @@ module Airbrake
53
53
  # occurring exceptions.
54
54
  attr_accessor :ignore_environments
55
55
 
56
+ ##
57
+ # @return [Integer] The HTTP timeout in seconds.
58
+ attr_accessor :timeout
59
+
56
60
  ##
57
61
  # @param [Hash{Symbol=>Object}] user_config the hash to be used to build the
58
62
  # config
@@ -70,6 +74,8 @@ module Airbrake
70
74
 
71
75
  self.ignore_environments = []
72
76
 
77
+ self.timeout = user_config[:timeout]
78
+
73
79
  merge(user_config)
74
80
  end
75
81
 
@@ -55,7 +55,13 @@ module Airbrake
55
55
 
56
56
  def filter_url_params(url)
57
57
  url.query = Hash[URI.decode_www_form(url.query)].map do |key, val|
58
- should_filter?(key) ? "#{key}=[Filtered]" : "#{key}=#{val}"
58
+ # Ruby < 2.2 raises InvalidComponentError if the query contains
59
+ # invalid characters, so be sure to escape individual components.
60
+ if should_filter?(key)
61
+ "#{URI.encode_www_form_component(key)}=[Filtered]"
62
+ else
63
+ "#{URI.encode_www_form_component(key)}=#{URI.encode_www_form_component(val)}"
64
+ end
59
65
  end.join('&')
60
66
 
61
67
  url.to_s
@@ -52,6 +52,10 @@ module Airbrake
52
52
  def build_https(uri)
53
53
  Net::HTTP.new(uri.host, uri.port, *proxy_params).tap do |https|
54
54
  https.use_ssl = uri.is_a?(URI::HTTPS)
55
+ if @config.timeout
56
+ https.open_timeout = @config.timeout
57
+ https.read_timeout = @config.timeout
58
+ end
55
59
  end
56
60
  end
57
61
 
@@ -3,5 +3,5 @@
3
3
  module Airbrake
4
4
  ##
5
5
  # @return [String] the library version
6
- AIRBRAKE_RUBY_VERSION = '1.0.4'.freeze
6
+ AIRBRAKE_RUBY_VERSION = '1.1.0'.freeze
7
7
  end
@@ -6,20 +6,25 @@ RSpec.describe Airbrake::AsyncSender do
6
6
  end
7
7
 
8
8
  describe "#send" do
9
- it "limits the size of the queue, but still sends all notices" do
9
+ it "limits the size of the queue" do
10
10
  stdout = StringIO.new
11
11
  notices_count = 1000
12
+ queue_size = 10
12
13
  config = Airbrake::Config.new(
13
- logger: Logger.new(stdout), workers: 3, queue_size: 10
14
+ logger: Logger.new(stdout), workers: 3, queue_size: queue_size
14
15
  )
15
16
  sender = described_class.new(config)
16
17
  expect(sender).to have_workers
17
18
 
18
- notices_count.times { |i| sender.send(i) }
19
+ notice = Airbrake::Notice.new(config, AirbrakeTestError.new)
20
+ notices_count.times { sender.send(notice) }
19
21
  sender.close
20
22
 
21
23
  log = stdout.string.split("\n")
22
- expect(log.grep(/\*\*Airbrake: \{\}/).size).to eq(notices_count)
24
+ notices_sent = log.grep(/\*\*Airbrake: \{\}/).size
25
+ notices_dropped = log.grep(/\*\*Airbrake:.*not.*delivered/).size
26
+ expect(notices_sent).to be >= queue_size
27
+ expect(notices_sent + notices_dropped).to eq(notices_count)
23
28
  end
24
29
  end
25
30
 
@@ -43,7 +48,8 @@ RSpec.describe Airbrake::AsyncSender do
43
48
 
44
49
  context "when there are some unsent notices" do
45
50
  before do
46
- 300.times { |i| @sender.send(i) }
51
+ notice = Airbrake::Notice.new(Airbrake::Config.new, AirbrakeTestError.new)
52
+ 300.times { @sender.send(notice) }
47
53
  expect(@sender.instance_variable_get(:@unsent).size).not_to be_zero
48
54
  @sender.close
49
55
  end
@@ -52,9 +58,12 @@ RSpec.describe Airbrake::AsyncSender do
52
58
  expect(@stderr.string).to match(/waiting to send \d+ unsent notice/)
53
59
  end
54
60
 
55
- it "prints the debug message the correct number of times" do
61
+ it "prints the correct number of log messages" do
56
62
  log = @stderr.string.split("\n")
57
- expect(log.grep(/\*\*Airbrake: \{\}/).size).to eq(300)
63
+ notices_sent = log.grep(/\*\*Airbrake: \{\}/).size
64
+ notices_dropped = log.grep(/\*\*Airbrake:.*not.*delivered/).size
65
+ expect(notices_sent).to be >= @sender.instance_variable_get(:@unsent).max
66
+ expect(notices_sent + notices_dropped).to eq(300)
58
67
  end
59
68
 
60
69
  it "waits until the unsent notices queue is empty" do
@@ -62,6 +62,10 @@ RSpec.describe Airbrake::Config do
62
62
  it "doesn't set default notify_environments" do
63
63
  expect(config.ignore_environments).to be_empty
64
64
  end
65
+
66
+ it "doesn't set default timeout" do
67
+ expect(config.timeout).to be_nil
68
+ end
65
69
  end
66
70
  end
67
71
  end
@@ -539,13 +539,13 @@ RSpec.describe Airbrake::Notifier do
539
539
  @airbrake.blacklist_keys(%w(bish))
540
540
 
541
541
  notice = @airbrake.build_notice(ex)
542
- notice[:context][:url] = 'http://localhost:3000/crash?foo=bar&baz=bongo&bish=bash'
542
+ notice[:context][:url] = 'http://localhost:3000/crash?foo=bar&baz=bongo&bish=bash&color=%23FFAAFF'
543
543
 
544
544
  @airbrake.notify_sync(notice)
545
545
 
546
546
  # rubocop:disable Metrics/LineLength
547
547
  expected_body =
548
- %r("context":{.*"url":"http://localhost:3000/crash\?foo=bar&baz=bongo&bish=\[Filtered\]".*})
548
+ %r("context":{.*"url":"http://localhost:3000/crash\?foo=bar&baz=bongo&bish=\[Filtered\]&color=%23FFAAFF".*})
549
549
  # rubocop:enable Metrics/LineLength
550
550
 
551
551
  expect(
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Airbrake::SyncSender do
4
+ describe "#build_https" do
5
+ it "overrides Net::HTTP's open_timeout and read_timeout if timeout is specified" do
6
+ config = Airbrake::Config.new(timeout: 10)
7
+ sender = described_class.new(config)
8
+ https = sender.__send__(:build_https, config.endpoint)
9
+ expect(https.open_timeout).to eq(10)
10
+ expect(https.read_timeout).to eq(10)
11
+ end
12
+ end
13
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airbrake Technologies, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-02 00:00:00.000000000 Z
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -122,6 +122,7 @@ files:
122
122
  - spec/notifier_spec/options_spec.rb
123
123
  - spec/payload_truncator_spec.rb
124
124
  - spec/spec_helper.rb
125
+ - spec/sync_sender_spec.rb
125
126
  homepage: https://airbrake.io
126
127
  licenses:
127
128
  - MIT
@@ -147,15 +148,15 @@ signing_key:
147
148
  specification_version: 4
148
149
  summary: Ruby notifier for https://airbrake.io
149
150
  test_files:
150
- - spec/notifier_spec/options_spec.rb
151
- - spec/async_sender_spec.rb
152
- - spec/spec_helper.rb
153
- - spec/notifier_spec.rb
154
- - spec/payload_truncator_spec.rb
155
151
  - spec/airbrake_spec.rb
152
+ - spec/async_sender_spec.rb
156
153
  - spec/backtrace_spec.rb
157
- - spec/nested_exception_spec.rb
158
- - spec/notice_spec.rb
159
154
  - spec/config_spec.rb
160
155
  - spec/filter_chain_spec.rb
161
- has_rdoc:
156
+ - spec/nested_exception_spec.rb
157
+ - spec/notice_spec.rb
158
+ - spec/notifier_spec/options_spec.rb
159
+ - spec/notifier_spec.rb
160
+ - spec/payload_truncator_spec.rb
161
+ - spec/spec_helper.rb
162
+ - spec/sync_sender_spec.rb