airbrake-ruby 4.13.1 → 4.13.3

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
  SHA256:
3
- metadata.gz: 29f58448d31db594854b99c73fd6574b326f7943215f6c5e89b4407bf254add5
4
- data.tar.gz: 2f2d9bd955015731f70abc13a6dafd3a73002567cea3b0b8b6bb0a1ae456a8be
3
+ metadata.gz: 63e544ab7354b30c5a8f4e3e73ba22daf9f27a0e3d4804e3bf015f38b34a6314
4
+ data.tar.gz: f2d238127b26e3fdfdc1b7848f847760993a87d15182ec7266e42d7db753609c
5
5
  SHA512:
6
- metadata.gz: 52380ea7f5f9288dd967c70fc01f238cd22eb3d1b335dd05962d4b4b7c037b9fec385e32f5f036d7059a012799895dd0f168f5a3e7f0241d4d26690e822490a6
7
- data.tar.gz: 65fbb12a214ea879b6b69405950f11d2c7d599f09bc1735e90bb3744e86f021482bf44e996a8392270bf6c6818294899eb9c0c672c25f8cd1a188ed5995f45fc
6
+ metadata.gz: 759ab3e188a8c20f2363e6aabdda6634f278b87cf24a67ecaad3998dde0dfe9de856ad8ca44f6a068b22afc2f8dcd7408ab66be6010ec3090cd2b52eef4434d8
7
+ data.tar.gz: 845c5c487af401362663273c85d56fb924578332a227ba534ced253d954af17ebdade9c6d5346a8e9640fcb4c8583ad068c8c43d0bc85fa7ec41298aff07c978
@@ -1,7 +1,6 @@
1
1
  require 'net/https'
2
2
  require 'logger'
3
3
  require 'json'
4
- require 'thread'
5
4
  require 'set'
6
5
  require 'socket'
7
6
  require 'time'
@@ -582,6 +581,7 @@ module Airbrake
582
581
  notice_notifier.add_filter(whitelist)
583
582
  end
584
583
 
584
+ return if configured?
585
585
  return unless config.root_directory
586
586
 
587
587
  [
@@ -7,12 +7,6 @@ module Airbrake
7
7
  class AsyncSender
8
8
  include Loggable
9
9
 
10
- # @return [String]
11
- WILL_NOT_DELIVER_MSG =
12
- "%<log_label>s AsyncSender has reached its capacity of %<capacity>s " \
13
- "and the following notice will not be delivered " \
14
- "Error: %<type>s - %<message>s\nBacktrace: %<backtrace>s\n".freeze
15
-
16
10
  def initialize(method = :post)
17
11
  @config = Airbrake::Config.instance
18
12
  @method = method
@@ -20,12 +14,13 @@ module Airbrake
20
14
 
21
15
  # Asynchronously sends a notice to Airbrake.
22
16
  #
23
- # @param [Airbrake::Notice] notice A notice that was generated by the
24
- # library
17
+ # @param [Hash] payload Whatever needs to be sent
25
18
  # @return [Airbrake::Promise]
26
- def send(notice, promise, endpoint = @config.endpoint)
27
- unless thread_pool << [notice, promise, endpoint]
28
- return will_not_deliver(notice, promise)
19
+ def send(payload, promise, endpoint = @config.endpoint)
20
+ unless thread_pool << [payload, promise, endpoint]
21
+ return promise.reject(
22
+ "AsyncSender has reached its capacity of #{@config.queue_size}",
23
+ )
29
24
  end
30
25
 
31
26
  promise
@@ -58,23 +53,5 @@ module Airbrake
58
53
  )
59
54
  end
60
55
  end
61
-
62
- def will_not_deliver(notice, promise)
63
- error = notice[:errors].first
64
-
65
- logger.error(
66
- format(
67
- WILL_NOT_DELIVER_MSG,
68
- log_label: LOG_LABEL,
69
- capacity: @config.queue_size,
70
- type: error[:type],
71
- message: error[:message],
72
- backtrace: error[:backtrace].map do |line|
73
- "#{line[:file]}:#{line[:line]} in `#{line[:function]}'"
74
- end.join("\n"),
75
- ),
76
- )
77
- promise.reject("AsyncSender has reached its capacity of #{@config.queue_size}")
78
- end
79
56
  end
80
57
  end
@@ -24,7 +24,18 @@ module Airbrake
24
24
 
25
25
  # @return [Array<Symbol>] parts of a Notice's *context* payload that can
26
26
  # be modified by blacklist/whitelist filters
27
- FILTERABLE_CONTEXT_KEYS = %i[user headers].freeze
27
+ FILTERABLE_CONTEXT_KEYS = %i[
28
+ user
29
+
30
+ # Provided by Airbrake::Rack::HttpHeadersFilter
31
+ headers
32
+ referer
33
+ httpMethod
34
+
35
+ # Provided by Airbrake::Rack::ContextFilter
36
+ userAddr
37
+ userAgent
38
+ ].freeze
28
39
 
29
40
  include Loggable
30
41
 
@@ -76,7 +76,7 @@ module Airbrake
76
76
  #
77
77
  # @return [Hash{String=>String}, nil]
78
78
  # @api private
79
- def to_json
79
+ def to_json(*_args)
80
80
  loop do
81
81
  begin
82
82
  json = @payload.to_json
@@ -9,7 +9,7 @@ module Airbrake
9
9
  # @return [Array<Class>] filters to be executed first
10
10
  DEFAULT_FILTERS = [
11
11
  Airbrake::Filters::SystemExitFilter,
12
- Airbrake::Filters::GemRootFilter
12
+ Airbrake::Filters::GemRootFilter,
13
13
 
14
14
  # Optional filters (must be included by users):
15
15
  # Airbrake::Filters::ThreadFilter
@@ -24,18 +24,21 @@ module Airbrake
24
24
  @sum = sum
25
25
  @sumsq = sumsq
26
26
  @tdigest = tdigest
27
+ @mutex = Mutex.new
27
28
  end
28
29
 
29
30
  # @return [Hash{String=>Object}] stats as a hash with compressed TDigest
30
31
  # (serialized as base64)
31
32
  def to_h
32
- tdigest.compress!
33
- {
34
- 'count' => tdigest.size,
35
- 'sum' => sum,
36
- 'sumsq' => sumsq,
37
- 'tdigest' => Base64.strict_encode64(tdigest.as_small_bytes),
38
- }
33
+ @mutex.synchronize do
34
+ tdigest.compress!
35
+ {
36
+ 'count' => tdigest.size,
37
+ 'sum' => sum,
38
+ 'sumsq' => sumsq,
39
+ 'tdigest' => Base64.strict_encode64(tdigest.as_small_bytes),
40
+ }
41
+ end
39
42
  end
40
43
 
41
44
  # Increments tdigest timings and updates tdigest with the difference between
@@ -54,10 +57,12 @@ module Airbrake
54
57
  # @param [Float] ms
55
58
  # @return [void]
56
59
  def increment_ms(ms)
57
- self.sum += ms
58
- self.sumsq += ms * ms
60
+ @mutex.synchronize do
61
+ self.sum += ms
62
+ self.sumsq += ms * ms
59
63
 
60
- tdigest.push(ms)
64
+ tdigest.push(ms)
65
+ end
61
66
  end
62
67
 
63
68
  # We define custom inspect so that we weed out uninformative TDigest, which
@@ -45,7 +45,15 @@ module Airbrake
45
45
  # @return [Boolean] true if the message was successfully sent to the pool,
46
46
  # false if the queue is full
47
47
  def <<(message)
48
- return false if backlog >= @queue_size
48
+ if backlog >= @queue_size
49
+ logger.error(
50
+ "#{LOG_LABEL} ThreadPool has reached its capacity of " \
51
+ "#{@queue_size} and the following message will not be " \
52
+ "processed: #{message.inspect}",
53
+ )
54
+ return false
55
+ end
56
+
49
57
  @queue << message
50
58
  true
51
59
  end
@@ -2,5 +2,5 @@
2
2
  # More information: http://semver.org/
3
3
  module Airbrake
4
4
  # @return [String] the library version
5
- AIRBRAKE_RUBY_VERSION = '4.13.1'.freeze
5
+ AIRBRAKE_RUBY_VERSION = '4.13.3'.freeze
6
6
  end
@@ -75,6 +75,16 @@ RSpec.describe Airbrake do
75
75
  described_class.configure {}
76
76
  expect(described_class.deploy_notifier).to eql(deploy_notifier)
77
77
  end
78
+
79
+ it "doesn't append the same notice notifier filters over and over" do
80
+ described_class.configure do |c|
81
+ c.project_id = 1
82
+ c.project_key = '2'
83
+ end
84
+
85
+ expect(described_class.notice_notifier).not_to receive(:add_filter)
86
+ 10.times { described_class.configure {} }
87
+ end
78
88
  end
79
89
 
80
90
  context "when blacklist_keys gets configured" do
@@ -58,15 +58,6 @@ RSpec.describe Airbrake::AsyncSender do
58
58
  'error' => "AsyncSender has reached its capacity of 1",
59
59
  )
60
60
  end
61
-
62
- it "logs discarded notice" do
63
- expect(Airbrake::Loggable.instance).to receive(:error).with(
64
- /reached its capacity/,
65
- ).at_least(:once)
66
-
67
- 15.times { subject.send(notice, Airbrake::Promise.new) }
68
- subject.close
69
- end
70
61
  end
71
62
  end
72
63
  end
@@ -51,6 +51,15 @@ RSpec.describe Airbrake::ThreadPool do
51
51
 
52
52
  expect(tasks.size).to be_zero
53
53
  end
54
+
55
+ it "logs discarded tasks" do
56
+ expect(Airbrake::Loggable.instance).to receive(:error).with(
57
+ /reached its capacity/,
58
+ ).exactly(15).times
59
+
60
+ 15.times { subject << 1 }
61
+ subject.close
62
+ end
54
63
  end
55
64
  end
56
65
 
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: 4.13.1
4
+ version: 4.13.3
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: 2020-02-11 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbtree3