airbrake-ruby 4.10.1 → 4.11.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
  SHA256:
3
- metadata.gz: 48ada7ef05512e70461f565b7d0f501d3109c1b6934449106cb5006bdb7281db
4
- data.tar.gz: 343e472ce390b3882543423bdb8ee50a4cc311ff3907f557a553fa57631305d7
3
+ metadata.gz: 6b9d78ba8789ccfa27f139a5ad0fef6b544da9bde4239dfda22cc543493bdb45
4
+ data.tar.gz: c32c7e64425037221491c64de8e22d548815929ec6e3a0289aad3c74f8ffedc7
5
5
  SHA512:
6
- metadata.gz: 7d68da52b648cff0b0e4c64016f5e0dd6d0143f1cf547e5604ed41ee58f9f03511e689c3acd35eef7df632d998cb56a416212ff1c952c9331ec173459641c20c
7
- data.tar.gz: '079ac6ce90ab7b885561e7f17ab6d770630d59cbaa066664c2b0c2cabd4c28b2c594101863ef04b8e4a92e369ac5e9f3c886159f227eec370a485544cf035250'
6
+ metadata.gz: 711d058e48af32390e7b92243171014122b5e454cea35afd19ca72e5fe39d04b919f0cbc95dfdf23685a3114cac14430310eb5a0c785c263d85a52ca26bab861
7
+ data.tar.gz: 300176c0bab2a6ddcb4b3453069be19ef5a477021ca10f68256edabc97c9d0d15b3b4a5659f2676e53071f89229b59c90ac6d0f1016d953342af8d9fc8b27581
@@ -328,9 +328,8 @@ module Airbrake
328
328
  notice_notifier.merge_context(context)
329
329
  end
330
330
 
331
- # Increments request statistics of a certain +route+ that was invoked on
332
- # +start_time+ and ended on +end_time+ with +method+, and returned
333
- # +status_code+.
331
+ # Increments request statistics of a certain +route+ invoked with +method+,
332
+ # which returned +status_code+.
334
333
  #
335
334
  # After a certain amount of time (n seconds) the aggregated route
336
335
  # information will be sent to Airbrake.
@@ -343,8 +342,7 @@ module Airbrake
343
342
  # func: 'do_stuff',
344
343
  # file: 'app/models/foo.rb',
345
344
  # line: 452,
346
- # start_time: timestamp,
347
- # end_time: Time.now
345
+ # timing: 123.45 # ms
348
346
  # )
349
347
  #
350
348
  # @param [Hash{Symbol=>Object}] request_info
@@ -358,8 +356,8 @@ module Airbrake
358
356
  # called the query (optional)
359
357
  # @option request_info [Integer] :line The line that executes the query
360
358
  # (optional)
361
- # @option request_info [Date] :start_time When the request started
362
- # @option request_info [Time] :end_time When the request ended (optional)
359
+ # @option request_info [Float] :timing How much time it took to process the
360
+ # request (in ms)
363
361
  # @param [Hash] stash What needs to be appeneded to the stash, so it's
364
362
  # available in filters
365
363
  # @return [void]
@@ -371,9 +369,8 @@ module Airbrake
371
369
  performance_notifier.notify(request)
372
370
  end
373
371
 
374
- # Synchronously Increments request statistics of a certain +route+ that was
375
- # invoked on +start_time+ and ended on +end_time+ with +method+, and
376
- # returned +status_code+.
372
+ # Synchronously increments request statistics of a certain +route+ invoked
373
+ # with +method+, which returned +status_code+.
377
374
  # @since v4.10.0
378
375
  # @see .notify_request
379
376
  def notify_request_sync(request_info, stash = {})
@@ -382,9 +379,8 @@ module Airbrake
382
379
  performance_notifier.notify_sync(request)
383
380
  end
384
381
 
385
- # Increments SQL statistics of a certain +query+ that was invoked on
386
- # +start_time+ and finished on +end_time+. When +method+ and +route+ are
387
- # provided, the query is grouped by these parameters.
382
+ # Increments SQL statistics of a certain +query+. When +method+ and +route+
383
+ # are provided, the query is grouped by these parameters.
388
384
  #
389
385
  # After a certain amount of time (n seconds) the aggregated query
390
386
  # information will be sent to Airbrake.
@@ -394,18 +390,17 @@ module Airbrake
394
390
  # method: 'GET',
395
391
  # route: '/things',
396
392
  # query: 'SELECT * FROM things',
397
- # start_time: timestamp,
398
- # end_time: Time.now
393
+ # timing: 123.45 # ms
399
394
  # )
400
395
  #
401
396
  # @param [Hash{Symbol=>Object}] query_info
402
- # @option request_info [String] :method The HTTP method that triggered this
397
+ # @option query_info [String] :method The HTTP method that triggered this
403
398
  # SQL query (optional)
404
- # @option request_info [String] :route The route that triggered this SQL
399
+ # @option query_info [String] :route The route that triggered this SQL
405
400
  # query (optional)
406
- # @option request_info [String] :query The query that was executed
407
- # @option request_info [Date] :start_time When the query started executing
408
- # @option request_info [Time] :end_time When the query finished (optional)
401
+ # @option query_info [String] :query The query that was executed
402
+ # @option query_info [Float] :timing How much time it took to process the
403
+ # query (in ms)
409
404
  # @param [Hash] stash What needs to be appeneded to the stash, so it's
410
405
  # available in filters
411
406
  # @return [void]
@@ -417,9 +412,9 @@ module Airbrake
417
412
  performance_notifier.notify(query)
418
413
  end
419
414
 
420
- # Synchronously increments SQL statistics of a certain +query+ that was
421
- # invoked on +start_time+ and finished on +end_time+. When +method+ and
422
- # +route+ are provided, the query is grouped by these parameters.
415
+ # Synchronously increments SQL statistics of a certain +query+. When
416
+ # +method+ and +route+ are provided, the query is grouped by these
417
+ # parameters.
423
418
  # @since v4.10.0
424
419
  # @see .notify_query
425
420
  def notify_query_sync(query_info, stash = {})
@@ -436,8 +431,7 @@ module Airbrake
436
431
  # route: '/thing/:id/create',
437
432
  # response_type: 'json',
438
433
  # groups: { db: 24.0, view: 0.4 }, # ms
439
- # start_time: timestamp,
440
- # end_time: Time.now
434
+ # timing: 123.45 # ms
441
435
  # )
442
436
  #
443
437
  # @param [Hash{Symbol=>Object}] breakdown_info
@@ -445,7 +439,8 @@ module Airbrake
445
439
  # @option breakdown_info [String] :route
446
440
  # @option breakdown_info [String] :response_type
447
441
  # @option breakdown_info [Array<Hash{Symbol=>Float}>] :groups
448
- # @option breakdown_info [Date] :start_time
442
+ # @option breakdown_info [Float] :timing How much time it took to process
443
+ # the performance breakdown (in ms)
449
444
  # @param [Hash] stash What needs to be appeneded to the stash, so it's
450
445
  # available in filters
451
446
  # @return [void]
@@ -481,6 +476,8 @@ module Airbrake
481
476
  # failed
482
477
  # @option queue_info [Array<Hash{Symbol=>Float}>] :groups Where the job
483
478
  # spent its time
479
+ # @option breakdown_info [Float] :timing How much time it took to process
480
+ # the queue (in ms)
484
481
  # @param [Hash] stash What needs to be appended to the stash, so it's
485
482
  # available in filters
486
483
  # @return [void]
@@ -2,7 +2,7 @@ module Airbrake
2
2
  # Benchmark benchmarks Ruby code.
3
3
  #
4
4
  # @since v4.2.4
5
- # @api private
5
+ # @api public
6
6
  class Benchmark
7
7
  # Measures monotonic time for the given operation.
8
8
  #
@@ -55,7 +55,8 @@ module Airbrake
55
55
  def build_notice(exception, params = {})
56
56
  if @async_sender.closed?
57
57
  raise Airbrake::Error,
58
- "attempted to build #{exception} with closed Airbrake instance"
58
+ "Airbrake is closed; can't build exception: " \
59
+ "#{exception.class}: #{exception}"
59
60
  end
60
61
 
61
62
  if exception.is_a?(Airbrake::Notice)
@@ -7,7 +7,8 @@ module Airbrake
7
7
  # @since v4.2.0
8
8
  # rubocop:disable Metrics/BlockLength, Metrics/ParameterLists
9
9
  PerformanceBreakdown = Struct.new(
10
- :method, :route, :response_type, :groups, :start_time, :end_time
10
+ :method, :route, :response_type, :groups, :start_time, :end_time, :timing,
11
+ :time
11
12
  ) do
12
13
  include HashKeyable
13
14
  include Ignorable
@@ -19,11 +20,15 @@ module Airbrake
19
20
  route:,
20
21
  response_type:,
21
22
  groups:,
22
- start_time:,
23
- end_time: start_time + 1
23
+ start_time: Time.now,
24
+ end_time: start_time + 1,
25
+ timing: nil,
26
+ time: Time.now
24
27
  )
25
- @start_time_utc = TimeTruncate.utc_truncate_minutes(start_time)
26
- super(method, route, response_type, groups, start_time, end_time)
28
+ @time_utc = TimeTruncate.utc_truncate_minutes(time)
29
+ super(
30
+ method, route, response_type, groups, start_time, end_time, timing, time
31
+ )
27
32
  end
28
33
 
29
34
  def destination
@@ -39,7 +44,7 @@ module Airbrake
39
44
  'method' => method,
40
45
  'route' => route,
41
46
  'responseType' => response_type,
42
- 'time' => @start_time_utc,
47
+ 'time' => @time_utc,
43
48
  }.delete_if { |_key, val| val.nil? }
44
49
  end
45
50
  end
@@ -62,7 +62,7 @@ module Airbrake
62
62
  @payload[resource] = { total: Airbrake::Stat.new }
63
63
  end
64
64
 
65
- @payload[resource][:total].increment(resource.start_time, resource.end_time)
65
+ update_total(resource, @payload[resource][:total])
66
66
 
67
67
  resource.groups.each do |name, ms|
68
68
  @payload[resource][name] ||= Airbrake::Stat.new
@@ -70,6 +70,19 @@ module Airbrake
70
70
  end
71
71
  end
72
72
 
73
+ def update_total(resource, total)
74
+ if resource.timing
75
+ total.increment_ms(resource.timing)
76
+ else
77
+ loc = caller_locations(6..6).first
78
+ Kernel.warn(
79
+ "#{loc.path}:#{loc.lineno}: warning: :start_time and :end_time are " \
80
+ "deprecated. Use :timing & :time instead",
81
+ )
82
+ total.increment(resource.start_time, resource.end_time)
83
+ end
84
+ end
85
+
73
86
  def schedule_flush
74
87
  return if @payload.empty?
75
88
 
@@ -107,14 +120,13 @@ module Airbrake
107
120
  end
108
121
 
109
122
  def send_resource(resource, sync:)
110
- promise = @config.check_configuration
111
- return promise if promise.rejected?
112
-
113
- promise = @config.check_performance_options(resource)
123
+ promise = check_configuration(resource)
114
124
  return promise if promise.rejected?
115
125
 
116
126
  @filter_chain.refine(resource)
117
- return if resource.ignored?
127
+ if resource.ignored?
128
+ return Promise.new.reject("#{resource.class} was ignored by a filter")
129
+ end
118
130
 
119
131
  @mutex.synchronize do
120
132
  update_payload(resource)
@@ -126,6 +138,20 @@ module Airbrake
126
138
  end
127
139
  end
128
140
 
141
+ def check_configuration(resource)
142
+ promise = @config.check_configuration
143
+ return promise if promise.rejected?
144
+
145
+ promise = @config.check_performance_options(resource)
146
+ return promise if promise.rejected?
147
+
148
+ if resource.timing && resource.timing == 0
149
+ return Promise.new.reject(':timing cannot be zero')
150
+ end
151
+
152
+ Promise.new
153
+ end
154
+
129
155
  def send(sender, payload, promise)
130
156
  signature = "#{self.class.name}##{__method__}"
131
157
  raise "#{signature}: payload (#{payload}) cannot be empty. Race?" if payload.none?
@@ -6,7 +6,8 @@ module Airbrake
6
6
  # @since v3.2.0
7
7
  # rubocop:disable Metrics/ParameterLists, Metrics/BlockLength
8
8
  Query = Struct.new(
9
- :method, :route, :query, :func, :file, :line, :start_time, :end_time
9
+ :method, :route, :query, :func, :file, :line, :start_time, :end_time,
10
+ :timing, :time
10
11
  ) do
11
12
  include HashKeyable
12
13
  include Ignorable
@@ -21,11 +22,16 @@ module Airbrake
21
22
  func: nil,
22
23
  file: nil,
23
24
  line: nil,
24
- start_time:,
25
- end_time: start_time + 1
25
+ start_time: Time.now,
26
+ end_time: start_time + 1,
27
+ timing: nil,
28
+ time: Time.now
26
29
  )
27
- @start_time_utc = TimeTruncate.utc_truncate_minutes(start_time)
28
- super(method, route, query, func, file, line, start_time, end_time)
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
+ )
29
35
  end
30
36
 
31
37
  def destination
@@ -41,7 +47,7 @@ module Airbrake
41
47
  'method' => method,
42
48
  'route' => route,
43
49
  'query' => query,
44
- 'time' => @start_time_utc,
50
+ 'time' => @time_utc,
45
51
  'function' => func,
46
52
  'file' => file,
47
53
  'line' => line,
@@ -4,8 +4,10 @@ module Airbrake
4
4
  # @see Airbrake.notify_queue
5
5
  # @api public
6
6
  # @since v4.9.0
7
- # rubocop:disable Metrics/BlockLength
8
- Queue = Struct.new(:queue, :error_count, :groups, :start_time, :end_time) do
7
+ # rubocop:disable Metrics/BlockLength, Metrics/ParameterLists
8
+ Queue = Struct.new(
9
+ :queue, :error_count, :groups, :start_time, :end_time, :timing, :time
10
+ ) do
9
11
  include HashKeyable
10
12
  include Ignorable
11
13
  include Stashable
@@ -15,10 +17,12 @@ module Airbrake
15
17
  error_count:,
16
18
  groups: {},
17
19
  start_time: Time.now,
18
- end_time: start_time + 1
20
+ end_time: start_time + 1,
21
+ timing: nil,
22
+ time: Time.now
19
23
  )
20
- @start_time_utc = TimeTruncate.utc_truncate_minutes(start_time)
21
- super(queue, error_count, groups, start_time, end_time)
24
+ @time_utc = TimeTruncate.utc_truncate_minutes(time)
25
+ super(queue, error_count, groups, start_time, end_time, timing, time)
22
26
  end
23
27
 
24
28
  def destination
@@ -33,14 +37,14 @@ module Airbrake
33
37
  {
34
38
  'queue' => queue,
35
39
  'errorCount' => error_count,
36
- 'time' => @start_time_utc,
40
+ 'time' => @time_utc,
37
41
  }
38
42
  end
39
43
 
40
44
  def hash
41
45
  {
42
46
  'queue' => queue,
43
- 'time' => @start_time_utc,
47
+ 'time' => @time_utc,
44
48
  }.hash
45
49
  end
46
50
 
@@ -48,5 +52,5 @@ module Airbrake
48
52
  self.error_count += other.error_count
49
53
  end
50
54
  end
51
- # rubocop:enable Metrics/BlockLength
55
+ # rubocop:enable Metrics/BlockLength, Metrics/ParameterLists
52
56
  end
@@ -4,8 +4,10 @@ module Airbrake
4
4
  # @see Airbrake.notify_request
5
5
  # @api public
6
6
  # @since v3.2.0
7
- # rubocop:disable Metrics/BlockLength
8
- Request = Struct.new(:method, :route, :status_code, :start_time, :end_time) do
7
+ # rubocop:disable Metrics/BlockLength, Metrics/ParameterLists
8
+ Request = Struct.new(
9
+ :method, :route, :status_code, :start_time, :end_time, :timing, :time
10
+ ) do
9
11
  include HashKeyable
10
12
  include Ignorable
11
13
  include Stashable
@@ -16,11 +18,13 @@ module Airbrake
16
18
  method:,
17
19
  route:,
18
20
  status_code:,
19
- start_time:,
20
- end_time: start_time + 1
21
+ start_time: Time.now,
22
+ end_time: start_time + 1,
23
+ timing: nil,
24
+ time: Time.now
21
25
  )
22
- @start_time_utc = TimeTruncate.utc_truncate_minutes(start_time)
23
- super(method, route, status_code, start_time, end_time)
26
+ @time_utc = TimeTruncate.utc_truncate_minutes(time)
27
+ super(method, route, status_code, start_time, end_time, timing, time)
24
28
  end
25
29
 
26
30
  def destination
@@ -36,9 +40,9 @@ module Airbrake
36
40
  'method' => method,
37
41
  'route' => route,
38
42
  'statusCode' => status_code,
39
- 'time' => @start_time_utc,
43
+ 'time' => @time_utc,
40
44
  }.delete_if { |_key, val| val.nil? }
41
45
  end
42
46
  end
43
- # rubocop:enable Metrics/BlockLength
47
+ # rubocop:enable Metrics/BlockLength, Metrics/ParameterLists
44
48
  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.10.1'.freeze
5
+ AIRBRAKE_RUBY_VERSION = '4.11.1'.freeze
6
6
  end
@@ -171,7 +171,7 @@ RSpec.describe Airbrake do
171
171
  method: 'GET',
172
172
  route: '/',
173
173
  status_code: 200,
174
- start_time: Time.now,
174
+ timing: 1,
175
175
  )
176
176
  end
177
177
  end
@@ -187,7 +187,7 @@ RSpec.describe Airbrake do
187
187
  method: 'GET',
188
188
  route: '/',
189
189
  status_code: 200,
190
- start_time: Time.now,
190
+ timing: 1,
191
191
  },
192
192
  request_id: 1,
193
193
  )
@@ -204,7 +204,7 @@ RSpec.describe Airbrake do
204
204
  method: 'GET',
205
205
  route: '/',
206
206
  status_code: 200,
207
- start_time: Time.now,
207
+ timing: 1,
208
208
  },
209
209
  request_id: 1,
210
210
  )
@@ -222,7 +222,7 @@ RSpec.describe Airbrake do
222
222
  method: 'GET',
223
223
  route: '/',
224
224
  query: '',
225
- start_time: Time.now,
225
+ timing: 1,
226
226
  )
227
227
  end
228
228
  end
@@ -238,7 +238,7 @@ RSpec.describe Airbrake do
238
238
  method: 'GET',
239
239
  route: '/',
240
240
  query: '',
241
- start_time: Time.now,
241
+ timing: 1,
242
242
  },
243
243
  request_id: 1,
244
244
  )
@@ -255,7 +255,7 @@ RSpec.describe Airbrake do
255
255
  method: 'GET',
256
256
  route: '/',
257
257
  query: '',
258
- start_time: Time.now,
258
+ timing: 1,
259
259
  },
260
260
  request_id: 1,
261
261
  )
@@ -273,7 +273,7 @@ RSpec.describe Airbrake do
273
273
  method: 'GET',
274
274
  route: '/',
275
275
  query: '',
276
- start_time: Time.now,
276
+ timing: 1,
277
277
  )
278
278
  end
279
279
  end
@@ -292,7 +292,7 @@ RSpec.describe Airbrake do
292
292
  route: '/',
293
293
  response_type: :html,
294
294
  groups: {},
295
- start_time: Time.now,
295
+ timing: 1,
296
296
  },
297
297
  request_id: 1,
298
298
  )
@@ -310,7 +310,7 @@ RSpec.describe Airbrake do
310
310
  route: '/',
311
311
  response_type: :html,
312
312
  groups: {},
313
- start_time: Time.now,
313
+ timing: 1,
314
314
  },
315
315
  request_id: 1,
316
316
  )
@@ -110,9 +110,7 @@ RSpec.describe Airbrake::Config do
110
110
 
111
111
  describe "#check_performance_options" do
112
112
  it "returns a promise" do
113
- resource = Airbrake::Query.new(
114
- method: '', route: '', query: '', start_time: Time.now,
115
- )
113
+ resource = Airbrake::Query.new(method: '', route: '', query: '', timing: 1)
116
114
  expect(subject.check_performance_options(resource))
117
115
  .to be_an(Airbrake::Promise)
118
116
  end
@@ -122,7 +120,7 @@ RSpec.describe Airbrake::Config do
122
120
 
123
121
  let(:resource) do
124
122
  Airbrake::Request.new(
125
- method: 'GET', route: '/foo', status_code: 200, start_time: Time.new,
123
+ method: 'GET', route: '/foo', status_code: 200, timing: 1,
126
124
  )
127
125
  end
128
126
 
@@ -138,9 +136,7 @@ RSpec.describe Airbrake::Config do
138
136
  before { subject.query_stats = false }
139
137
 
140
138
  let(:resource) do
141
- Airbrake::Query.new(
142
- method: 'GET', route: '/foo', query: '', start_time: Time.new,
143
- )
139
+ Airbrake::Query.new(method: 'GET', route: '/foo', query: '', timing: 1)
144
140
  end
145
141
 
146
142
  it "returns a rejected promise" do
@@ -13,9 +13,7 @@ RSpec.describe Airbrake::Filters::SqlFilter do
13
13
  shared_examples "query blacklisting" do |query, opts|
14
14
  it "ignores '#{query}'" do
15
15
  filter = described_class.new('postgres')
16
- q = Airbrake::Query.new(
17
- query: query, method: 'GET', route: '/', start_time: Time.now,
18
- )
16
+ q = Airbrake::Query.new(query: query, method: 'GET', route: '/', timing: 1)
19
17
  filter.call(q)
20
18
 
21
19
  expect(q.ignored?).to eq(opts[:should_ignore])
@@ -328,9 +328,9 @@ RSpec.describe Airbrake::NoticeNotifier do
328
328
  end
329
329
 
330
330
  it "raises error" do
331
- expect { subject.build_notice(Exception.new) }.to raise_error(
331
+ expect { subject.build_notice(Exception.new('oops')) }.to raise_error(
332
332
  Airbrake::Error,
333
- 'attempted to build Exception with closed Airbrake instance',
333
+ "Airbrake is closed; can't build exception: Exception: oops",
334
334
  )
335
335
  end
336
336
  end
@@ -29,8 +29,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
29
29
  func: 'foo',
30
30
  file: 'foo.rb',
31
31
  line: 123,
32
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
33
- end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
32
+ timing: 60000,
33
+ time: Time.new(2018, 1, 1, 0, 49, 0, 0),
34
34
  ),
35
35
  )
36
36
  subject.close
@@ -59,8 +59,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
59
59
  method: 'POST',
60
60
  route: '/foo',
61
61
  status_code: 200,
62
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
63
- end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
62
+ timing: 60000,
63
+ time: Time.new(2018, 1, 1, 0, 49, 0, 0),
64
64
  ),
65
65
  )
66
66
  subject.close
@@ -86,8 +86,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
86
86
  method: 'DELETE',
87
87
  route: '/routes-breakdowns',
88
88
  response_type: 'json',
89
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
90
- end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
89
+ timing: 60000,
90
+ time: Time.new(2018, 1, 1, 0, 49, 0, 0),
91
91
  groups: { db: 131, view: 421 },
92
92
  ),
93
93
  )
@@ -128,8 +128,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
128
128
  queue: 'emails',
129
129
  error_count: 2,
130
130
  groups: { redis: 131, sql: 421 },
131
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
132
- end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
131
+ timing: 60000,
132
+ time: Time.new(2018, 1, 1, 0, 49, 0, 0),
133
133
  ),
134
134
  )
135
135
  subject.close
@@ -168,7 +168,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
168
168
  method: 'GET',
169
169
  route: '/foo',
170
170
  status_code: 200,
171
- start_time: Time.new(2018, 1, 1, 0, 0, 20, 0),
171
+ timing: 60000,
172
+ time: Time.new(2018, 1, 1, 0, 0, 20, 0),
172
173
  ),
173
174
  )
174
175
  subject.close
@@ -184,7 +185,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
184
185
  method: 'GET',
185
186
  route: '/foo',
186
187
  status_code: 200,
187
- start_time: Time.new(2018, 1, 1, 0, 0, 20, 0),
188
+ timing: 213,
188
189
  ),
189
190
  )
190
191
  subject.notify(
@@ -192,7 +193,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
192
193
  method: 'GET',
193
194
  route: '/foo',
194
195
  status_code: 200,
195
- start_time: Time.new(2018, 1, 1, 0, 0, 50, 0),
196
+ timing: 123,
196
197
  ),
197
198
  )
198
199
  subject.close
@@ -208,8 +209,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
208
209
  method: 'GET',
209
210
  route: '/foo',
210
211
  status_code: 200,
211
- start_time: Time.new(2018, 1, 1, 0, 0, 49, 0),
212
- end_time: Time.new(2018, 1, 1, 0, 0, 50, 0),
212
+ timing: 1000,
213
+ time: Time.new(2018, 1, 1, 0, 0, 49, 0),
213
214
  ),
214
215
  )
215
216
  subject.notify(
@@ -217,8 +218,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
217
218
  method: 'GET',
218
219
  route: '/foo',
219
220
  status_code: 200,
220
- start_time: Time.new(2018, 1, 1, 0, 1, 49, 0),
221
- end_time: Time.new(2018, 1, 1, 0, 1, 55, 0),
221
+ timing: 6000,
222
+ time: Time.new(2018, 1, 1, 0, 1, 49, 0),
222
223
  ),
223
224
  )
224
225
  subject.close
@@ -244,8 +245,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
244
245
  method: 'GET',
245
246
  route: '/foo',
246
247
  status_code: 200,
247
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
248
- end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
248
+ timing: 60000,
249
+ time: Time.new(2018, 1, 1, 0, 49, 0, 0),
249
250
  ),
250
251
  )
251
252
  subject.notify(
@@ -253,8 +254,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
253
254
  method: 'POST',
254
255
  route: '/foo',
255
256
  status_code: 200,
256
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
257
- end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
257
+ timing: 60000,
258
+ time: Time.new(2018, 1, 1, 0, 49, 0, 0),
258
259
  ),
259
260
  )
260
261
  subject.close
@@ -280,8 +281,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
280
281
  method: 'DELETE',
281
282
  route: '/routes-breakdowns',
282
283
  response_type: 'json',
283
- start_time: Time.new(2018, 1, 1, 0, 0, 20, 0),
284
- end_time: Time.new(2018, 1, 1, 0, 0, 22, 0),
284
+ timing: 2000,
285
+ time: Time.new(2018, 1, 1, 0, 0, 20, 0),
285
286
  groups: { db: 131, view: 421 },
286
287
  ),
287
288
  )
@@ -290,8 +291,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
290
291
  method: 'DELETE',
291
292
  route: '/routes-breakdowns',
292
293
  response_type: 'json',
293
- start_time: Time.new(2018, 1, 1, 0, 0, 30, 0),
294
- end_time: Time.new(2018, 1, 1, 0, 0, 32, 0),
294
+ timing: 2000,
295
+ time: Time.new(2018, 1, 1, 0, 0, 30, 0),
295
296
  groups: { db: 55, view: 11 },
296
297
  ),
297
298
  )
@@ -332,8 +333,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
332
333
  queue: 'emails',
333
334
  error_count: 2,
334
335
  groups: { redis: 131, sql: 421 },
335
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
336
- end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
336
+ timing: 60000,
337
+ time: Time.new(2018, 1, 1, 0, 49, 0, 0),
337
338
  ),
338
339
  )
339
340
  subject.notify(
@@ -341,8 +342,8 @@ RSpec.describe Airbrake::PerformanceNotifier do
341
342
  queue: 'emails',
342
343
  error_count: 3,
343
344
  groups: { redis: 131, sql: 421 },
344
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
345
- end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
345
+ timing: 60000,
346
+ time: Time.new(2018, 1, 1, 0, 49, 0, 0),
346
347
  ),
347
348
  )
348
349
  subject.close
@@ -381,7 +382,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
381
382
  method: 'GET',
382
383
  route: '/foo',
383
384
  status_code: 200,
384
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
385
+ timing: 123,
385
386
  ),
386
387
  )
387
388
  subject.close
@@ -392,7 +393,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
392
393
 
393
394
  it "checks performance stat configuration" do
394
395
  request = Airbrake::Request.new(
395
- method: 'GET', route: '/foo', status_code: 200, start_time: Time.new,
396
+ method: 'GET', route: '/foo', status_code: 200, timing: 123,
396
397
  )
397
398
  expect(Airbrake::Config.instance).to receive(:check_performance_options)
398
399
  .with(request).and_return(Airbrake::Promise.new)
@@ -408,7 +409,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
408
409
  method: 'POST',
409
410
  route: '/foo',
410
411
  status_code: 200,
411
- start_time: Time.new,
412
+ timing: 123,
412
413
  ),
413
414
  )
414
415
  subject.close
@@ -445,7 +446,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
445
446
  method: 'GET',
446
447
  route: '/foo',
447
448
  status_code: 200,
448
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
449
+ timing: 123,
449
450
  ),
450
451
  )
451
452
 
@@ -454,7 +455,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
454
455
  method: 'POST',
455
456
  route: '/foo',
456
457
  query: 'SELECT * FROM things',
457
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
458
+ timing: 123,
458
459
  ),
459
460
  )
460
461
 
@@ -474,7 +475,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
474
475
  method: 'GET',
475
476
  route: '/foo',
476
477
  status_code: 200,
477
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
478
+ timing: 1,
478
479
  ),
479
480
  )
480
481
  subject.close
@@ -488,13 +489,29 @@ RSpec.describe Airbrake::PerformanceNotifier do
488
489
  method: 'POST',
489
490
  route: '/foo',
490
491
  query: 'SELECT * FROM things',
491
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
492
+ timing: 1,
492
493
  ),
493
494
  )
494
495
  subject.close
495
496
 
496
497
  expect(a_request(:put, queries)).not_to have_been_made
497
498
  end
499
+
500
+ it "returns a rejected promise" do
501
+ promise = subject.notify(
502
+ Airbrake::Query.new(
503
+ method: 'POST',
504
+ route: '/foo',
505
+ query: 'SELECT * FROM things',
506
+ timing: 1,
507
+ ),
508
+ )
509
+ subject.close
510
+
511
+ expect(promise.value).to eq(
512
+ 'error' => 'Airbrake::Query was ignored by a filter',
513
+ )
514
+ end
498
515
  end
499
516
 
500
517
  context "when a filter that modifies payload was defined" do
@@ -510,7 +527,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
510
527
  method: 'POST',
511
528
  route: '/foo',
512
529
  query: 'SELECT * FROM things',
513
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
530
+ timing: 123,
514
531
  ),
515
532
  )
516
533
  subject.close
@@ -522,6 +539,49 @@ RSpec.describe Airbrake::PerformanceNotifier do
522
539
  ).to have_been_made
523
540
  end
524
541
  end
542
+
543
+ context "when :start_time is specified (deprecated)" do
544
+ before do
545
+ allow(Kernel).to receive(:warn)
546
+ end
547
+
548
+ it "uses the value of :start_time to update stat" do
549
+ subject.notify(
550
+ Airbrake::Query.new(
551
+ method: 'POST',
552
+ route: '/foo',
553
+ query: 'SELECT * FROM things',
554
+ start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
555
+ end_time: Time.new(2018, 1, 1, 0, 50, 0, 0),
556
+ ),
557
+ )
558
+ subject.close
559
+
560
+ expect(
561
+ a_request(:put, queries).with(
562
+ body: /"count":1,"sum":60000.0,"sumsq":3600000000.0/,
563
+ ),
564
+ ).to have_been_made
565
+ end
566
+ end
567
+
568
+ context "when provided :timing is zero" do
569
+ it "doesn't notify" do
570
+ queue = Airbrake::Queue.new(queue: 'bananas', error_count: 0, timing: 0)
571
+ subject.notify(queue)
572
+ subject.close
573
+
574
+ expect(a_request(:put, queues)).not_to have_been_made
575
+ end
576
+
577
+ it "returns a rejected promise" do
578
+ queue = Airbrake::Queue.new(queue: 'bananas', error_count: 0, timing: 0)
579
+ promise = subject.notify(queue)
580
+ subject.close
581
+
582
+ expect(promise.value).to eq('error' => ':timing cannot be zero')
583
+ end
584
+ end
525
585
  end
526
586
 
527
587
  describe "#notify_sync" do
@@ -531,7 +591,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
531
591
  method: 'POST',
532
592
  route: '/foo',
533
593
  query: 'SELECT * FROM things',
534
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
594
+ timing: 123,
535
595
  ),
536
596
  )
537
597
 
@@ -560,7 +620,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
560
620
  method: 'POST',
561
621
  route: '/foo',
562
622
  query: 'SELECT * FROM things',
563
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
623
+ timing: 123,
564
624
  ),
565
625
  )
566
626
  subject.close
@@ -591,7 +651,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
591
651
  method: 'POST',
592
652
  route: '/foo',
593
653
  status_code: 200,
594
- start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
654
+ timing: 123,
595
655
  ),
596
656
  )
597
657
  subject.close
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.10.1
4
+ version: 4.11.1
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-12 00:00:00.000000000 Z
11
+ date: 2019-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbtree3