airbrake-ruby 4.11.1 → 4.13.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
  SHA256:
3
- metadata.gz: 6b9d78ba8789ccfa27f139a5ad0fef6b544da9bde4239dfda22cc543493bdb45
4
- data.tar.gz: c32c7e64425037221491c64de8e22d548815929ec6e3a0289aad3c74f8ffedc7
3
+ metadata.gz: 21b45126851240764d75da35e8f7fbc7c73effdda1b01854065dc25db0c351e3
4
+ data.tar.gz: 5dd7a704b0a16a841fb93b30b72a0acf28cb887f2e7abdda57e48078289d107b
5
5
  SHA512:
6
- metadata.gz: 711d058e48af32390e7b92243171014122b5e454cea35afd19ca72e5fe39d04b919f0cbc95dfdf23685a3114cac14430310eb5a0c785c263d85a52ca26bab861
7
- data.tar.gz: 300176c0bab2a6ddcb4b3453069be19ef5a477021ca10f68256edabc97c9d0d15b3b4a5659f2676e53071f89229b59c90ac6d0f1016d953342af8d9fc8b27581
6
+ metadata.gz: 9252437e39b4a415e2e90ca8a4434540ecd7e45737bdacd788e772a308fbc6c1f231c293eaa11aaaf90310f695f7a44e87b7511cd5af204259949746a6e85013
7
+ data.tar.gz: 969b2e55a423d02f241e04ccb27eeb13d352dbe3b0f4394c53dccdf4a3bab8c4d59e19ac7a9c7e455a08b5c22340e49b126581b1be90adcd972faaa79fbb6e11
@@ -84,6 +84,13 @@ module Airbrake
84
84
  # special cases where we need to work around older implementations
85
85
  JRUBY = (RUBY_ENGINE == 'jruby')
86
86
 
87
+ # @return [Boolean] true if this Ruby supports safe levels and tainting,
88
+ # to guard against using deprecated or unsupported features.
89
+ HAS_SAFE_LEVEL = (
90
+ RUBY_ENGINE == 'ruby' &&
91
+ Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.7')
92
+ )
93
+
87
94
  class << self
88
95
  # @since v4.2.3
89
96
  # @api private
@@ -364,7 +371,7 @@ module Airbrake
364
371
  # @since v3.0.0
365
372
  # @see Airbrake::PerformanceNotifier#notify
366
373
  def notify_request(request_info, stash = {})
367
- request = Request.new(request_info)
374
+ request = Request.new(**request_info)
368
375
  request.stash.merge!(stash)
369
376
  performance_notifier.notify(request)
370
377
  end
@@ -374,7 +381,7 @@ module Airbrake
374
381
  # @since v4.10.0
375
382
  # @see .notify_request
376
383
  def notify_request_sync(request_info, stash = {})
377
- request = Request.new(request_info)
384
+ request = Request.new(**request_info)
378
385
  request.stash.merge!(stash)
379
386
  performance_notifier.notify_sync(request)
380
387
  end
@@ -407,7 +414,7 @@ module Airbrake
407
414
  # @since v3.2.0
408
415
  # @see Airbrake::PerformanceNotifier#notify
409
416
  def notify_query(query_info, stash = {})
410
- query = Query.new(query_info)
417
+ query = Query.new(**query_info)
411
418
  query.stash.merge!(stash)
412
419
  performance_notifier.notify(query)
413
420
  end
@@ -418,7 +425,7 @@ module Airbrake
418
425
  # @since v4.10.0
419
426
  # @see .notify_query
420
427
  def notify_query_sync(query_info, stash = {})
421
- query = Query.new(query_info)
428
+ query = Query.new(**query_info)
422
429
  query.stash.merge!(stash)
423
430
  performance_notifier.notify_sync(query)
424
431
  end
@@ -446,7 +453,7 @@ module Airbrake
446
453
  # @return [void]
447
454
  # @since v4.2.0
448
455
  def notify_performance_breakdown(breakdown_info, stash = {})
449
- performance_breakdown = PerformanceBreakdown.new(breakdown_info)
456
+ performance_breakdown = PerformanceBreakdown.new(**breakdown_info)
450
457
  performance_breakdown.stash.merge!(stash)
451
458
  performance_notifier.notify(performance_breakdown)
452
459
  end
@@ -456,7 +463,7 @@ module Airbrake
456
463
  # @since v4.10.0
457
464
  # @see .notify_performance_breakdown
458
465
  def notify_performance_breakdown_sync(breakdown_info, stash = {})
459
- performance_breakdown = PerformanceBreakdown.new(breakdown_info)
466
+ performance_breakdown = PerformanceBreakdown.new(**breakdown_info)
460
467
  performance_breakdown.stash.merge!(stash)
461
468
  performance_notifier.notify_sync(performance_breakdown)
462
469
  end
@@ -484,7 +491,7 @@ module Airbrake
484
491
  # @since v4.9.0
485
492
  # @see .notify_queue_sync
486
493
  def notify_queue(queue_info, stash = {})
487
- queue = Queue.new(queue_info)
494
+ queue = Queue.new(**queue_info)
488
495
  queue.stash.merge!(stash)
489
496
  performance_notifier.notify(queue)
490
497
  end
@@ -493,7 +500,7 @@ module Airbrake
493
500
  # @since v4.10.0
494
501
  # @see .notify_queue
495
502
  def notify_queue_sync(queue_info, stash = {})
496
- queue = Queue.new(queue_info)
503
+ queue = Queue.new(**queue_info)
497
504
  queue.stash.merge!(stash)
498
505
  performance_notifier.notify_sync(queue)
499
506
  end
@@ -101,6 +101,12 @@ module Airbrake
101
101
  # @since v4.6.0
102
102
  attr_accessor :query_stats
103
103
 
104
+ # @return [Boolean] true if the library should send job/queue/worker stats
105
+ # to Airbrake, false otherwise
106
+ # @api public
107
+ # @since v4.12.0
108
+ attr_accessor :job_stats
109
+
104
110
  class << self
105
111
  # @return [Config]
106
112
  attr_writer :instance
@@ -139,6 +145,7 @@ module Airbrake
139
145
  self.performance_stats = true
140
146
  self.performance_stats_flush_period = 15
141
147
  self.query_stats = true
148
+ self.job_stats = true
142
149
 
143
150
  merge(user_config)
144
151
  end
@@ -213,6 +220,8 @@ module Airbrake
213
220
  promise.reject("The Performance Stats feature is disabled")
214
221
  elsif resource.is_a?(Airbrake::Query) && !query_stats
215
222
  promise.reject("The Query Stats feature is disabled")
223
+ elsif resource.is_a?(Airbrake::Queue) && !job_stats
224
+ promise.reject("The Job Stats feature is disabled")
216
225
  else
217
226
  promise
218
227
  end
@@ -72,7 +72,7 @@ module Airbrake
72
72
  thread_info[:group] = th.group.list.map(&:inspect)
73
73
  thread_info[:priority] = th.priority
74
74
 
75
- thread_info[:safe_level] = th.safe_level unless Airbrake::JRUBY
75
+ thread_info[:safe_level] = th.safe_level if Airbrake::HAS_SAFE_LEVEL
76
76
  end
77
77
 
78
78
  def sanitize_value(value)
@@ -5,16 +5,16 @@ module Airbrake
5
5
  # @see Airbrake.notify_breakdown
6
6
  # @api public
7
7
  # @since v4.2.0
8
- # rubocop:disable Metrics/BlockLength, Metrics/ParameterLists
9
- PerformanceBreakdown = Struct.new(
10
- :method, :route, :response_type, :groups, :start_time, :end_time, :timing,
11
- :time
12
- ) do
8
+ # rubocop:disable Metrics/ParameterLists
9
+ class PerformanceBreakdown
13
10
  include HashKeyable
14
11
  include Ignorable
15
12
  include Stashable
16
13
  include Mergeable
17
14
 
15
+ attr_accessor :method, :route, :response_type, :groups, :start_time,
16
+ :end_time, :timing, :time
17
+
18
18
  def initialize(
19
19
  method:,
20
20
  route:,
@@ -26,9 +26,14 @@ module Airbrake
26
26
  time: Time.now
27
27
  )
28
28
  @time_utc = TimeTruncate.utc_truncate_minutes(time)
29
- super(
30
- method, route, response_type, groups, start_time, end_time, timing, time
31
- )
29
+ @method = method
30
+ @route = route
31
+ @response_type = response_type
32
+ @groups = groups
33
+ @start_time = start_time
34
+ @end_time = end_time
35
+ @timing = timing
36
+ @time = time
32
37
  end
33
38
 
34
39
  def destination
@@ -48,5 +53,5 @@ module Airbrake
48
53
  }.delete_if { |_key, val| val.nil? }
49
54
  end
50
55
  end
51
- # rubocop:enable Metrics/BlockLength, Metrics/ParameterLists
56
+ # rubocop:enable Metrics/ParameterLists
52
57
  end
@@ -4,17 +4,17 @@ module Airbrake
4
4
  # @see Airbrake.notify_query
5
5
  # @api public
6
6
  # @since v3.2.0
7
- # rubocop:disable Metrics/ParameterLists, Metrics/BlockLength
8
- Query = Struct.new(
9
- :method, :route, :query, :func, :file, :line, :start_time, :end_time,
10
- :timing, :time
11
- ) do
7
+ # rubocop:disable Metrics/ParameterLists
8
+ class Query
12
9
  include HashKeyable
13
10
  include Ignorable
14
11
  include Stashable
15
12
  include Mergeable
16
13
  include Grouppable
17
14
 
15
+ attr_accessor :method, :route, :query, :func, :file, :line, :start_time,
16
+ :end_time, :timing, :time
17
+
18
18
  def initialize(
19
19
  method:,
20
20
  route:,
@@ -28,10 +28,16 @@ module Airbrake
28
28
  time: Time.now
29
29
  )
30
30
  @time_utc = TimeTruncate.utc_truncate_minutes(time)
31
- super(
32
- method, route, query, func, file, line, start_time, end_time, timing,
33
- time
34
- )
31
+ @method = method
32
+ @route = route
33
+ @query = query
34
+ @func = func
35
+ @file = file
36
+ @line = line
37
+ @start_time = start_time
38
+ @end_time = end_time
39
+ @timing = timing
40
+ @time = time
35
41
  end
36
42
 
37
43
  def destination
@@ -53,6 +59,6 @@ module Airbrake
53
59
  'line' => line,
54
60
  }.delete_if { |_key, val| val.nil? }
55
61
  end
56
- # rubocop:enable Metrics/ParameterLists, Metrics/BlockLength
62
+ # rubocop:enable Metrics/ParameterLists
57
63
  end
58
64
  end
@@ -4,14 +4,15 @@ module Airbrake
4
4
  # @see Airbrake.notify_queue
5
5
  # @api public
6
6
  # @since v4.9.0
7
- # rubocop:disable Metrics/BlockLength, Metrics/ParameterLists
8
- Queue = Struct.new(
9
- :queue, :error_count, :groups, :start_time, :end_time, :timing, :time
10
- ) do
7
+ # rubocop:disable Metrics/ParameterLists
8
+ class Queue
11
9
  include HashKeyable
12
10
  include Ignorable
13
11
  include Stashable
14
12
 
13
+ attr_accessor :queue, :error_count, :groups, :start_time, :end_time,
14
+ :timing, :time
15
+
15
16
  def initialize(
16
17
  queue:,
17
18
  error_count:,
@@ -22,7 +23,13 @@ module Airbrake
22
23
  time: Time.now
23
24
  )
24
25
  @time_utc = TimeTruncate.utc_truncate_minutes(time)
25
- super(queue, error_count, groups, start_time, end_time, timing, time)
26
+ @queue = queue
27
+ @error_count = error_count
28
+ @groups = groups
29
+ @start_time = start_time
30
+ @end_time = end_time
31
+ @timing = timing
32
+ @time = time
26
33
  end
27
34
 
28
35
  def destination
@@ -51,6 +58,15 @@ module Airbrake
51
58
  def merge(other)
52
59
  self.error_count += other.error_count
53
60
  end
61
+
62
+ # Queues don't have routes, but we want to define this to make sure our
63
+ # filter API is consistent (other models define this property)
64
+ #
65
+ # @return [String] empty route
66
+ # @see https://github.com/airbrake/airbrake-ruby/pull/537
67
+ def route
68
+ ''
69
+ end
54
70
  end
55
- # rubocop:enable Metrics/BlockLength, Metrics/ParameterLists
71
+ # rubocop:enable Metrics/ParameterLists
56
72
  end
@@ -4,16 +4,17 @@ module Airbrake
4
4
  # @see Airbrake.notify_request
5
5
  # @api public
6
6
  # @since v3.2.0
7
- # rubocop:disable Metrics/BlockLength, Metrics/ParameterLists
8
- Request = Struct.new(
9
- :method, :route, :status_code, :start_time, :end_time, :timing, :time
10
- ) do
7
+ # rubocop:disable Metrics/ParameterLists
8
+ class Request
11
9
  include HashKeyable
12
10
  include Ignorable
13
11
  include Stashable
14
12
  include Mergeable
15
13
  include Grouppable
16
14
 
15
+ attr_accessor :method, :route, :status_code, :start_time, :end_time,
16
+ :timing, :time
17
+
17
18
  def initialize(
18
19
  method:,
19
20
  route:,
@@ -24,7 +25,13 @@ module Airbrake
24
25
  time: Time.now
25
26
  )
26
27
  @time_utc = TimeTruncate.utc_truncate_minutes(time)
27
- super(method, route, status_code, start_time, end_time, timing, time)
28
+ @method = method
29
+ @route = route
30
+ @status_code = status_code
31
+ @start_time = start_time
32
+ @end_time = end_time
33
+ @timing = timing
34
+ @time = time
28
35
  end
29
36
 
30
37
  def destination
@@ -44,5 +51,5 @@ module Airbrake
44
51
  }.delete_if { |_key, val| val.nil? }
45
52
  end
46
53
  end
47
- # rubocop:enable Metrics/BlockLength, Metrics/ParameterLists
54
+ # rubocop:enable Metrics/ParameterLists
48
55
  end
@@ -1,6 +1,5 @@
1
1
  require 'base64'
2
2
 
3
- # rubocop:disable Metrics/BlockLength
4
3
  module Airbrake
5
4
  # Stat is a data structure that allows accumulating performance data (route
6
5
  # performance, SQL query performance and such). It's powered by TDigests.
@@ -14,14 +13,19 @@ module Airbrake
14
13
  # stat.to_h # Pack and serialize data so it can be transmitted.
15
14
  #
16
15
  # @since v3.2.0
17
- Stat = Struct.new(:count, :sum, :sumsq, :tdigest) do
16
+ class Stat
17
+ attr_accessor :count, :sum, :sumsq, :tdigest
18
+
18
19
  # @param [Integer] count How many times this stat was incremented
19
20
  # @param [Float] sum The sum of duration in milliseconds
20
21
  # @param [Float] sumsq The squared sum of duration in milliseconds
21
22
  # @param [TDigest::TDigest] tdigest Packed durations. By default,
22
23
  # compression is 20
23
24
  def initialize(count: 0, sum: 0.0, sumsq: 0.0, tdigest: TDigest.new(0.05))
24
- super(count, sum, sumsq, tdigest)
25
+ @count = count
26
+ @sum = sum
27
+ @sumsq = sumsq
28
+ @tdigest = tdigest
25
29
  end
26
30
 
27
31
  # @return [Hash{String=>Object}] stats as a hash with compressed TDigest
@@ -67,7 +71,6 @@ module Airbrake
67
71
  def inspect
68
72
  "#<struct Airbrake::Stat count=#{count}, sum=#{sum}, sumsq=#{sumsq}>"
69
73
  end
70
- alias_method :pretty_print, :inspect
74
+ alias pretty_print inspect
71
75
  end
72
76
  end
73
- # rubocop:enable Metrics/BlockLength
@@ -108,8 +108,8 @@ module Airbrake
108
108
  return str if utf8_string && str.valid_encoding?
109
109
 
110
110
  temp_str = str.dup
111
- temp_str.encode!(TEMP_ENCODING, ENCODING_OPTIONS) if utf8_string
112
- temp_str.encode!('utf-8', ENCODING_OPTIONS)
111
+ temp_str.encode!(TEMP_ENCODING, **ENCODING_OPTIONS) if utf8_string
112
+ temp_str.encode!('utf-8', **ENCODING_OPTIONS)
113
113
  end
114
114
  end
115
115
  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.11.1'.freeze
5
+ AIRBRAKE_RUBY_VERSION = '4.13.0'.freeze
6
6
  end
@@ -22,6 +22,7 @@ RSpec.describe Airbrake::Config do
22
22
  its(:performance_stats) { is_expected.to eq(true) }
23
23
  its(:performance_stats_flush_period) { is_expected.to eq(15) }
24
24
  its(:query_stats) { is_expected.to eq(true) }
25
+ its(:job_stats) { is_expected.to eq(true) }
25
26
 
26
27
  describe "#new" do
27
28
  context "when user config is passed" do
@@ -146,5 +147,20 @@ RSpec.describe Airbrake::Config do
146
147
  )
147
148
  end
148
149
  end
150
+
151
+ context "when job stats are disabled" do
152
+ before { subject.job_stats = false }
153
+
154
+ let(:resource) do
155
+ Airbrake::Queue.new(queue: 'foo_queue', error_count: 0, timing: 1)
156
+ end
157
+
158
+ it "returns a rejected promise" do
159
+ promise = subject.check_performance_options(resource)
160
+ expect(promise.value).to eq(
161
+ 'error' => "The Job Stats feature is disabled",
162
+ )
163
+ end
164
+ end
149
165
  end
150
166
  end
@@ -258,7 +258,9 @@ RSpec.describe Airbrake::Filters::ThreadFilter do
258
258
  expect(notice[:params][:thread][:priority]).to eq(0)
259
259
  end
260
260
 
261
- it "appends safe_level", skip: Airbrake::JRUBY do
261
+ it "appends safe_level", skip: (
262
+ "Not supported on this version of Ruby." unless Airbrake::HAS_SAFE_LEVEL
263
+ ) do
262
264
  subject.call(notice)
263
265
  expect(notice[:params][:thread][:safe_level]).to eq(0)
264
266
  end
@@ -16,6 +16,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
16
16
  performance_stats: true,
17
17
  performance_stats_flush_period: 0,
18
18
  query_stats: true,
19
+ job_stats: true,
19
20
  )
20
21
  end
21
22
 
@@ -18,4 +18,13 @@ RSpec.describe Airbrake::Queue do
18
18
  expect(queue.end_time).to eq(time + 1)
19
19
  end
20
20
  end
21
+
22
+ describe "#route" do
23
+ it "always returns an empty route" do
24
+ queue = described_class.new(
25
+ queue: 'a', error_count: 0, start_time: Time.now,
26
+ )
27
+ expect(queue.route).to be_empty
28
+ end
29
+ end
21
30
  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: 4.11.1
4
+ version: 4.13.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: 2019-12-20 00:00:00.000000000 Z
11
+ date: 2020-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbtree3