airbrake-ruby 3.2.5 → 3.2.6

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: d82d2c4088a9f12a7b9f79f06bbd627e467ca41a
4
- data.tar.gz: 2d5a844aee8b9566bb707a6ba5b89f6b0534d770
3
+ metadata.gz: b8b74bf6222301b0773cbae98656cae5e7434dfe
4
+ data.tar.gz: f0c09f8d665390398e8226e624d5fb407927ab09
5
5
  SHA512:
6
- metadata.gz: c0bda142c168eeca50d9f73d6897c031d20bec58f2c1c9dbc1bbc4778fa3252025bfd56c8f0c1f7593b86fc632ac3f26a7a73d2edd5b84171c2701b4d7a0a94c
7
- data.tar.gz: 871e4d592b46053d231d5ef6611e7f0736cffd0d4b40dc1ac586c1f3fee86e06bb937b4df0ee6c27a34d1c343d59d161b34b3b76b358683dbfdaad3a7013e1a3
6
+ metadata.gz: b075a5d9a1d6b6d3d28fe5345140c0c5397a34e49e89d52cbd9ab4b99d9d4fc57e12641cbd354028b579263f8fa69a82e15f15938559f8e905f553d0092ce972
7
+ data.tar.gz: 380596bb7dc0836185ac4a812fd309d5c3c5913b72177e4df660c620d9ae29520c9659bdcb01ccb52879e4946e37687231205b72a6191dbd1c177f2b3ad591aa
@@ -15,6 +15,7 @@ require 'airbrake-ruby/async_sender'
15
15
  require 'airbrake-ruby/response'
16
16
  require 'airbrake-ruby/nested_exception'
17
17
  require 'airbrake-ruby/ignorable'
18
+ require 'airbrake-ruby/inspectable'
18
19
  require 'airbrake-ruby/notice'
19
20
  require 'airbrake-ruby/backtrace'
20
21
  require 'airbrake-ruby/truncator'
@@ -78,6 +79,7 @@ require 'airbrake-ruby/request'
78
79
  #
79
80
  # @see Airbrake::NoticeNotifier
80
81
  # @since v1.0.0
82
+ # rubocop:disable Metrics/ModuleLength
81
83
  module Airbrake
82
84
  # The general error that this library uses when it wants to raise.
83
85
  Error = Class.new(StandardError)
@@ -190,6 +192,13 @@ module Airbrake
190
192
  # @return [Airbrake::NoticeNotifier, NilClass]
191
193
  # @since v1.8.0
192
194
  def [](notifier_name)
195
+ loc = caller_locations(1..1).first
196
+ signature = "#{self}##{__method__}"
197
+ warn(
198
+ "#{loc.path}:#{loc.lineno}: warning: #{signature} is deprecated. It " \
199
+ "will be removed from airbrake-ruby v4 altogether."
200
+ )
201
+
193
202
  @notice_notifiers[notifier_name]
194
203
  end
195
204
 
@@ -197,6 +206,13 @@ module Airbrake
197
206
  # (notice, performance, deploy)
198
207
  # @since v3.2.0
199
208
  def notifiers
209
+ loc = caller_locations(1..1).first
210
+ signature = "#{self}##{__method__}"
211
+ warn(
212
+ "#{loc.path}:#{loc.lineno}: warning: #{signature} is deprecated. It " \
213
+ "will be removed from airbrake-ruby v4 altogether."
214
+ )
215
+
200
216
  {
201
217
  notice: @notice_notifiers,
202
218
  performance: @performance_notifiers,
@@ -204,8 +220,7 @@ module Airbrake
204
220
  }
205
221
  end
206
222
 
207
- # Configures a new +notifier+ with the given name. If the name is not given,
208
- # configures the default notifier.
223
+ # Configures the Airbrake notifier.
209
224
  #
210
225
  # @example Configuring the default notifier
211
226
  # Airbrake.configure do |c|
@@ -213,14 +228,6 @@ module Airbrake
213
228
  # c.project_key = 'fd04e13d806a90f96614ad8e529b2822'
214
229
  # end
215
230
  #
216
- # @example Configuring a named notifier
217
- # # Configure a new Airbrake instance and
218
- # # assign +:my_other_project+ as its name.
219
- # Airbrake.configure(:my_other_project) do |c|
220
- # c.project_id = 224854
221
- # c.project_key = '91ac5e4a37496026c6837f63276ed2b6'
222
- # end
223
- #
224
231
  # @param [Symbol] notifier_name the name to be associated with the notifier
225
232
  # @yield [config] The configuration object
226
233
  # @yieldparam config [Airbrake::Config]
@@ -232,6 +239,15 @@ module Airbrake
232
239
  # @note There's no way to reconfigure a notifier
233
240
  # @note There's no way to read config values outside of this library
234
241
  def configure(notifier_name = :default)
242
+ unless notifier_name == :default
243
+ loc = caller_locations(1..1).first
244
+ warn(
245
+ "#{loc.path}:#{loc.lineno}: warning: configuring a notifier with a " \
246
+ "custom name is deprecated. This feature will be removed from " \
247
+ "airbrake-ruby v4 altogether."
248
+ )
249
+ end
250
+
235
251
  yield config = Airbrake::Config.new
236
252
 
237
253
  if @notice_notifiers.key?(notifier_name)
@@ -378,8 +394,7 @@ module Airbrake
378
394
  @notice_notifiers[:default].close
379
395
  end
380
396
 
381
- # Pings the Airbrake Deploy API endpoint about the occurred deploy. This
382
- # method is used by the airbrake gem for various integrations.
397
+ # Pings the Airbrake Deploy API endpoint about the occurred deploy.
383
398
  #
384
399
  # @param [Hash{Symbol=>String}] deploy_info The params for the API
385
400
  # @option deploy_info [Symbol] :environment
@@ -388,10 +403,21 @@ module Airbrake
388
403
  # @option deploy_info [Symbol] :revision
389
404
  # @option deploy_info [Symbol] :version
390
405
  # @return [void]
391
- def create_deploy(deploy_info)
406
+ def notify_deploy(deploy_info)
392
407
  @deploy_notifiers[:default].notify(deploy_info)
393
408
  end
394
409
 
410
+ # @see notify_deploy
411
+ def create_deploy(deploy_info)
412
+ loc = caller_locations(1..1).first
413
+ signature = "#{self}##{__method__}"
414
+ warn(
415
+ "#{loc.path}:#{loc.lineno}: warning: #{signature} is deprecated. Call " \
416
+ "#{self}#notify_deploy instead"
417
+ )
418
+ notify_deploy(deploy_info)
419
+ end
420
+
395
421
  # Merges +context+ with the current context.
396
422
  #
397
423
  # The context will be attached to the notice object upon a notify call and
@@ -565,3 +591,4 @@ module Airbrake
565
591
  end
566
592
  end
567
593
  end
594
+ # rubocop:enable Metrics/ModuleLength
@@ -10,6 +10,8 @@ module Airbrake
10
10
  # @api public
11
11
  # @since v3.2.0
12
12
  class DeployNotifier
13
+ include Inspectable
14
+
13
15
  # @param [Airbrake::Config] config
14
16
  def initialize(config)
15
17
  @config =
@@ -0,0 +1,39 @@
1
+ module Airbrake
2
+ # Inspectable provides custom inspect methods that reduce clutter printed in
3
+ # REPLs for notifier objects. These custom methods display only essential
4
+ # information such as project id/key and filters.
5
+ #
6
+ # @since v3.2.6
7
+ # @api private
8
+ module Inspectable
9
+ # @return [String] inspect output template
10
+ INSPECT_TEMPLATE =
11
+ "#<%<classname>s:0x%<id>s project_id=\"%<project_id>s\" " \
12
+ "project_key=\"%<project_key>s\" " \
13
+ "host=\"%<host>s\" filter_chain=%<filter_chain>s>".freeze
14
+
15
+ # @return [String] customized inspect to lessen the amount of clutter
16
+ def inspect
17
+ format(
18
+ INSPECT_TEMPLATE,
19
+ classname: self.class.name,
20
+ id: (object_id << 1).to_s(16).rjust(16, '0'),
21
+ project_id: @config.project_id,
22
+ project_key: @config.project_key,
23
+ host: @config.host,
24
+ filter_chain: @filter_chain.inspect
25
+ )
26
+ end
27
+
28
+ # @return [String] {#inspect} for PrettyPrint
29
+ def pretty_print(q)
30
+ q.text("#<#{self.class}:0x#{(object_id << 1).to_s(16).rjust(16, '0')} ")
31
+ q.text(
32
+ "project_id=\"#{@config.project_id}\" project_key=\"#{@config.project_key}\" " \
33
+ "host=\"#{@config.host}\" filter_chain="
34
+ )
35
+ q.pp(@filter_chain)
36
+ q.text('>')
37
+ end
38
+ end
39
+ end
@@ -7,15 +7,6 @@ module Airbrake
7
7
  # @api public
8
8
  # rubocop:disable Metrics/ClassLength
9
9
  class NoticeNotifier
10
- # @return [String] the label to be prepended to the log output
11
- LOG_LABEL = '**Airbrake:'.freeze
12
-
13
- # @return [String] inspect output template
14
- INSPECT_TEMPLATE =
15
- "#<#{self}:0x%<id>s project_id=\"%<project_id>s\" " \
16
- "project_key=\"%<project_key>s\" " \
17
- "host=\"%<host>s\" filter_chain=%<filter_chain>s>".freeze
18
-
19
10
  # @return [Array<Class>] filters to be executed first
20
11
  DEFAULT_FILTERS = [
21
12
  Airbrake::Filters::SystemExitFilter,
@@ -25,6 +16,8 @@ module Airbrake
25
16
  # Airbrake::Filters::ThreadFilter
26
17
  ].freeze
27
18
 
19
+ include Inspectable
20
+
28
21
  # Creates a new notice notifier with the given config options.
29
22
  #
30
23
  # @example
@@ -116,29 +109,6 @@ module Airbrake
116
109
  @context.merge!(context)
117
110
  end
118
111
 
119
- # @return [String] customized inspect to lessen the amount of clutter
120
- def inspect
121
- format(
122
- INSPECT_TEMPLATE,
123
- id: (object_id << 1).to_s(16).rjust(16, '0'),
124
- project_id: @config.project_id,
125
- project_key: @config.project_key,
126
- host: @config.host,
127
- filter_chain: @filter_chain.inspect
128
- )
129
- end
130
-
131
- # @return [String] {#inspect} for PrettyPrint
132
- def pretty_print(q)
133
- q.text("#<#{self.class}:0x#{(object_id << 1).to_s(16).rjust(16, '0')} ")
134
- q.text(
135
- "project_id=\"#{@config.project_id}\" project_key=\"#{@config.project_key}\" " \
136
- "host=\"#{@config.host}\" filter_chain="
137
- )
138
- q.pp(@filter_chain)
139
- q.text('>')
140
- end
141
-
142
112
  private
143
113
 
144
114
  def convert_to_exception(ex)
@@ -5,6 +5,8 @@ module Airbrake
5
5
  # @api public
6
6
  # @since v3.2.0
7
7
  class PerformanceNotifier
8
+ include Inspectable
9
+
8
10
  # @param [Airbrake::Config] config
9
11
  def initialize(config)
10
12
  @config =
@@ -85,6 +87,7 @@ module Airbrake
85
87
  end
86
88
  end
87
89
 
90
+ # rubocop:disable Metrics/AbcSize
88
91
  def send(payload, promise)
89
92
  signature = "#{self.class.name}##{__method__}"
90
93
  raise "#{signature}: payload (#{payload}) cannot be empty. Race?" if payload.none?
@@ -92,8 +95,11 @@ module Airbrake
92
95
  @config.logger.debug("#{LOG_LABEL} #{signature}: #{payload}")
93
96
 
94
97
  payload.group_by { |k, _v| k.name }.each do |resource_name, data|
98
+ data = { resource_name => data.map { |k, v| k.to_h.merge!(v.to_h) } }
99
+ data['environment'] = @config.environment if @config.environment
100
+
95
101
  @sender.send(
96
- { resource_name => data.map { |k, v| k.to_h.merge!(v.to_h) } },
102
+ data,
97
103
  promise,
98
104
  URI.join(
99
105
  @config.host,
@@ -102,5 +108,6 @@ module Airbrake
102
108
  )
103
109
  end
104
110
  end
111
+ # rubocop:enable Metrics/AbcSize
105
112
  end
106
113
  end
@@ -6,14 +6,12 @@ module Airbrake
6
6
  # @since v3.2.0
7
7
  # rubocop:disable Metrics/ParameterLists, Metrics/BlockLength
8
8
  Query = Struct.new(
9
- :environment, :method, :route, :query, :func, :file, :line, :start_time,
10
- :end_time
9
+ :method, :route, :query, :func, :file, :line, :start_time, :end_time
11
10
  ) do
12
11
  include HashKeyable
13
12
  include Ignorable
14
13
 
15
14
  def initialize(
16
- environment: nil,
17
15
  method:,
18
16
  route:,
19
17
  query:,
@@ -23,10 +21,7 @@ module Airbrake
23
21
  start_time:,
24
22
  end_time: Time.now
25
23
  )
26
- super(
27
- environment, method, route, query, func, file, line, start_time,
28
- end_time
29
- )
24
+ super(method, route, query, func, file, line, start_time, end_time)
30
25
  end
31
26
 
32
27
  def name
@@ -35,7 +30,6 @@ module Airbrake
35
30
 
36
31
  def to_h
37
32
  {
38
- 'environment' => environment,
39
33
  'method' => method,
40
34
  'route' => route,
41
35
  'query' => query,
@@ -4,22 +4,18 @@ module Airbrake
4
4
  # @see Airbrake.notify_request
5
5
  # @api public
6
6
  # @since v3.2.0
7
- # rubocop:disable Metrics/ParameterLists
8
- Request = Struct.new(
9
- :environment, :method, :route, :status_code, :start_time, :end_time
10
- ) do
7
+ Request = Struct.new(:method, :route, :status_code, :start_time, :end_time) do
11
8
  include HashKeyable
12
9
  include Ignorable
13
10
 
14
11
  def initialize(
15
- environment: nil,
16
12
  method:,
17
13
  route:,
18
14
  status_code:,
19
15
  start_time:,
20
16
  end_time: Time.now
21
17
  )
22
- super(environment, method, route, status_code, start_time, end_time)
18
+ super(method, route, status_code, start_time, end_time)
23
19
  end
24
20
 
25
21
  def name
@@ -28,7 +24,6 @@ module Airbrake
28
24
 
29
25
  def to_h
30
26
  {
31
- 'environment' => environment,
32
27
  'method' => method,
33
28
  'route' => route,
34
29
  'statusCode' => status_code,
@@ -36,5 +31,4 @@ module Airbrake
36
31
  }.delete_if { |_key, val| val.nil? }
37
32
  end
38
33
  end
39
- # rubocop:enable Metrics/ParameterLists
40
34
  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 = '3.2.5'.freeze
5
+ AIRBRAKE_RUBY_VERSION = '3.2.6'.freeze
6
6
  end
@@ -121,12 +121,12 @@ RSpec.describe Airbrake do
121
121
  end
122
122
  end
123
123
 
124
- describe ".create_deploy" do
124
+ describe ".notify_deploy" do
125
125
  let(:default_notifier) { described_class.notifiers[:deploy][:default] }
126
126
 
127
127
  it "calls 'notify' on the deploy notifier" do
128
128
  expect(default_notifier).to receive(:notify).with(foo: 'bar')
129
- described_class.create_deploy(foo: 'bar')
129
+ described_class.notify_deploy(foo: 'bar')
130
130
  end
131
131
  end
132
132
 
@@ -0,0 +1,45 @@
1
+ RSpec.describe Airbrake::Inspectable do
2
+ let(:klass) do
3
+ mod = subject
4
+ Class.new do
5
+ include(mod)
6
+
7
+ def initialize
8
+ @config = Airbrake::Config.new
9
+ @filter_chain = nil
10
+ end
11
+ end
12
+ end
13
+
14
+ describe "#inspect" do
15
+ it "displays object information" do
16
+ instance = klass.new
17
+ expect(instance.inspect).to match(/
18
+ #<:0x\w+\s
19
+ project_id=""\s
20
+ project_key=""\s
21
+ host="http.+"\s
22
+ filter_chain=nil>
23
+ /x)
24
+ end
25
+ end
26
+
27
+ describe "#pretty_print" do
28
+ it "displays object information in a beautiful way" do
29
+ q = PP.new
30
+
31
+ instance = klass.new
32
+ # Guarding is needed to fix JRuby failure:
33
+ # NoMethodError: undefined method `[]' for nil:NilClass
34
+ q.guard_inspect_key { instance.pretty_print(q) }
35
+
36
+ expect(q.output).to match(/
37
+ #<:0x\w+\s
38
+ project_id=""\s
39
+ project_key=""\s
40
+ host="http.+"\s
41
+ filter_chain=nil
42
+ /x)
43
+ end
44
+ end
45
+ end
@@ -402,35 +402,5 @@ RSpec.describe Airbrake::NoticeNotifier do
402
402
  subject.merge_context(apples: 'oranges')
403
403
  end
404
404
  end
405
-
406
- describe "#inspect" do
407
- it "displays object information" do
408
- expect(subject.inspect).to match(/
409
- #<Airbrake::NoticeNotifier:0x\w+\s
410
- project_id="\d+"\s
411
- project_key=".+"\s
412
- host="http.+"\s
413
- filter_chain=\[.+\]>
414
- /x)
415
- end
416
- end
417
-
418
- describe "#pretty_print" do
419
- it "displays object information in a beautiful way" do
420
- q = PP.new
421
-
422
- # Guarding is needed to fix JRuby failure:
423
- # NoMethodError: undefined method `[]' for nil:NilClass
424
- q.guard_inspect_key { subject.pretty_print(q) }
425
-
426
- expect(q.output).to match(/
427
- #<Airbrake::NoticeNotifier:0x\w+\s
428
- project_id="\d+"\s
429
- project_key=".+"\s
430
- host="http.+"\s
431
- filter_chain=\[\n\s\s
432
- /x)
433
- end
434
- end
435
405
  end
436
406
  # rubocop:enable Layout/DotPosition
@@ -22,7 +22,6 @@ RSpec.describe Airbrake::PerformanceNotifier do
22
22
  it "sends full query" do
23
23
  subject.notify(
24
24
  Airbrake::Query.new(
25
- environment: 'development',
26
25
  method: 'POST',
27
26
  route: '/foo',
28
27
  query: 'SELECT * FROM things',
@@ -37,7 +36,6 @@ RSpec.describe Airbrake::PerformanceNotifier do
37
36
  expect(
38
37
  a_request(:put, queries).with(body: %r|
39
38
  \A{"queries":\[{
40
- "environment":"development",
41
39
  "method":"POST",
42
40
  "route":"/foo",
43
41
  "query":"SELECT\s\*\sFROM\sthings",
@@ -56,7 +54,6 @@ RSpec.describe Airbrake::PerformanceNotifier do
56
54
  it "sends full request" do
57
55
  subject.notify(
58
56
  Airbrake::Request.new(
59
- environment: 'development',
60
57
  method: 'POST',
61
58
  route: '/foo',
62
59
  status_code: 200,
@@ -68,7 +65,6 @@ RSpec.describe Airbrake::PerformanceNotifier do
68
65
  expect(
69
66
  a_request(:put, routes).with(body: %r|
70
67
  \A{"routes":\[{
71
- "environment":"development",
72
68
  "method":"POST",
73
69
  "route":"/foo",
74
70
  "statusCode":200,
@@ -217,8 +213,7 @@ RSpec.describe Airbrake::PerformanceNotifier do
217
213
 
218
214
  it "doesn't send route stats when current environment is ignored" do
219
215
  notifier = described_class.new(
220
- Airbrake::Config.new(
221
- project_id: 1, project_key: '2', performance_stats: true,
216
+ config.merge(
222
217
  environment: 'test', ignore_environments: %w[test]
223
218
  )
224
219
  )
@@ -231,6 +226,28 @@ RSpec.describe Airbrake::PerformanceNotifier do
231
226
  expect(promise.value).to eq('error' => "The 'test' environment is ignored")
232
227
  end
233
228
 
229
+ it "sends environment when it's specified" do
230
+ notifier = described_class.new(
231
+ config.merge(
232
+ project_id: 1, project_key: '2', performance_stats: true,
233
+ environment: 'test'
234
+ )
235
+ )
236
+ notifier.notify(
237
+ Airbrake::Request.new(
238
+ method: 'POST',
239
+ route: '/foo',
240
+ status_code: 200,
241
+ start_time: Time.new
242
+ )
243
+ )
244
+ expect(
245
+ a_request(:put, routes).with(
246
+ body: /\A{"routes":\[.+\],"environment":"test"}\z/x
247
+ )
248
+ ).to have_been_made
249
+ end
250
+
234
251
  describe "payload grouping" do
235
252
  let(:flush_period) { 0.5 }
236
253
 
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: 3.2.5
4
+ version: 3.2.6
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-02-20 00:00:00.000000000 Z
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rbtree3
@@ -63,6 +63,7 @@ files:
63
63
  - lib/airbrake-ruby/filters/thread_filter.rb
64
64
  - lib/airbrake-ruby/hash_keyable.rb
65
65
  - lib/airbrake-ruby/ignorable.rb
66
+ - lib/airbrake-ruby/inspectable.rb
66
67
  - lib/airbrake-ruby/nested_exception.rb
67
68
  - lib/airbrake-ruby/notice.rb
68
69
  - lib/airbrake-ruby/notice_notifier.rb
@@ -107,6 +108,7 @@ files:
107
108
  - spec/fixtures/project_root/vendor/bundle/ignored_file.rb
108
109
  - spec/helpers.rb
109
110
  - spec/ignorable_spec.rb
111
+ - spec/inspectable_spec.rb
110
112
  - spec/nested_exception_spec.rb
111
113
  - spec/notice_notifier_spec.rb
112
114
  - spec/notice_notifier_spec/options_spec.rb
@@ -187,4 +189,5 @@ test_files:
187
189
  - spec/fixtures/project_root/code.rb
188
190
  - spec/fixtures/project_root/short_file.rb
189
191
  - spec/fixtures/project_root/vendor/bundle/ignored_file.rb
192
+ - spec/inspectable_spec.rb
190
193
  - spec/notice_notifier_spec/options_spec.rb