airbrake 5.7.1 → 5.8.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -141,6 +141,11 @@ RSpec.describe "Rails integration specs" do
141
141
  end
142
142
 
143
143
  context "when Airbrake is not configured" do
144
+ before do
145
+ # Make sure the Logger intergration doesn't get in the way.
146
+ allow_any_instance_of(Logger).to receive(:airbrake_notifier).and_return(nil)
147
+ end
148
+
144
149
  it "doesn't report errors" do
145
150
  allow(Airbrake).to receive(:build_notice).and_return(nil)
146
151
  allow(Airbrake).to receive(:notify)
@@ -216,6 +221,11 @@ RSpec.describe "Rails integration specs" do
216
221
  end
217
222
 
218
223
  context "when Airbrake is not configured" do
224
+ before do
225
+ # Make sure the Logger intergration doesn't get in the way.
226
+ allow_any_instance_of(Logger).to receive(:airbrake_notifier).and_return(nil)
227
+ end
228
+
219
229
  it "doesn't report errors" do
220
230
  allow(Airbrake).to receive(:build_notice).and_return(nil)
221
231
  allow(Airbrake).to receive(:notify)
@@ -12,6 +12,9 @@ RSpec.shared_examples 'rack examples' do
12
12
  end
13
13
 
14
14
  before do
15
+ # Make sure the Logger integration doesn't get in the way.
16
+ allow_any_instance_of(Logger).to receive(:airbrake_notifier).and_return(nil)
17
+
15
18
  stub_request(:post, endpoint).to_return(status: 201, body: '{}')
16
19
  end
17
20
 
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Logger do
4
+ let(:project_id) { 113743 }
5
+ let(:project_key) { 'fd04e13d806a90f96614ad8e529b2822' }
6
+
7
+ let(:endpoint) do
8
+ "https://airbrake.io/api/v3/projects/#{project_id}/notices?key=#{project_key}"
9
+ end
10
+
11
+ let(:airbrake) do
12
+ Airbrake::Notifier.new(project_id: project_id, project_key: project_key)
13
+ end
14
+
15
+ let(:logger) { Logger.new('/dev/null') }
16
+
17
+ def wait_for_a_request_with_body(body)
18
+ wait_for(a_request(:post, endpoint).with(body: body)).to have_been_made.once
19
+ end
20
+
21
+ before do
22
+ stub_request(:post, endpoint).to_return(status: 201, body: '{}')
23
+ end
24
+
25
+ describe "#airbrake" do
26
+ it "has the default notifier installed by default" do
27
+ expect(logger.airbrake_notifier).to be_an(Airbrake::Notifier)
28
+ end
29
+
30
+ it "installs Airbrake notifier" do
31
+ notifier_id = airbrake.object_id
32
+ expect(logger.airbrake_notifier.object_id).not_to eq(notifier_id)
33
+
34
+ logger.airbrake_notifier = airbrake
35
+ expect(logger.airbrake_notifier.object_id).to eq(notifier_id)
36
+ end
37
+ end
38
+
39
+ context "when Airbrake is installed" do
40
+ let(:out) { StringIO.new }
41
+ let(:logger) { Logger.new(out) }
42
+
43
+ before do
44
+ logger.airbrake_notifier = airbrake
45
+ end
46
+
47
+ it "both logs and notifies" do
48
+ msg = 'bingo'
49
+ logger.fatal(msg)
50
+
51
+ wait_for_a_request_with_body(/"message":"#{msg}"/)
52
+ expect(out.string).to match(/FATAL -- : #{msg}/)
53
+ end
54
+
55
+ it "sets the correct severity" do
56
+ logger.fatal('bango')
57
+ wait_for_a_request_with_body(/"context":{.*"severity":"critical".*}/)
58
+ end
59
+
60
+ it "sets the correct component" do
61
+ logger.fatal('bingo')
62
+ wait_for_a_request_with_body(/"component":"log"/)
63
+ end
64
+
65
+ it "strips out internal logger frames" do
66
+ logger.fatal('bongo')
67
+
68
+ wait_for(
69
+ a_request(:post, endpoint).
70
+ with(body: %r{"file":".+/logger.rb"})
71
+ ).not_to have_been_made
72
+ wait_for(a_request(:post, endpoint)).to have_been_made.once
73
+ end
74
+ end
75
+
76
+ describe "#airbrake_severity_level" do
77
+ context "when not set" do
78
+ it "defaults to Logger::WARN" do
79
+ expect(logger.airbrake_severity_level).to eq(Logger::WARN)
80
+ end
81
+ end
82
+
83
+ context "when set" do
84
+ before do
85
+ logger.airbrake_severity_level = Logger::FATAL
86
+ end
87
+
88
+ it "does not notify below the specified level" do
89
+ logger.error('bingo')
90
+ wait_for(a_request(:post, endpoint)).not_to have_been_made
91
+ end
92
+
93
+ it "notifies in the current or above level" do
94
+ logger.fatal('bingo')
95
+ wait_for(a_request(:post, endpoint)).to have_been_made
96
+ end
97
+ end
98
+ end
99
+
100
+ context "when Airbrake is not installed" do
101
+ it "only logs, never notifies" do
102
+ out = StringIO.new
103
+ l = Logger.new(out)
104
+ l.airbrake_notifier = nil
105
+ msg = 'bango'
106
+
107
+ l.fatal(msg)
108
+
109
+ wait_for(a_request(:post, endpoint)).not_to have_been_made
110
+ expect(out.string).to match('FATAL -- : bango')
111
+ end
112
+ end
113
+ end
@@ -51,7 +51,7 @@ RSpec.describe Airbrake::Rack::Middleware do
51
51
  stub_request(:post, bingo_endpoint).to_return(status: 201, body: '{}')
52
52
  end
53
53
 
54
- after { Airbrake.close(notifier_name) }
54
+ after { Airbrake[notifier_name].close }
55
55
 
56
56
  it "notifies via the specified notifier" do
57
57
  expect do
@@ -123,14 +123,14 @@ RSpec.describe Airbrake::Rack::Middleware do
123
123
 
124
124
  context "when Airbrake is not configured" do
125
125
  it "returns nil" do
126
- allow(Airbrake).to receive(:build_notice).and_return(nil)
127
- allow(Airbrake).to receive(:notify)
126
+ allow(Airbrake[:default]).to receive(:build_notice).and_return(nil)
127
+ allow(Airbrake[:default]).to receive(:notify)
128
128
 
129
129
  expect { described_class.new(faulty_app).call(env_for('/')) }.
130
130
  to raise_error(AirbrakeTestError)
131
131
 
132
- expect(Airbrake).to have_received(:build_notice)
133
- expect(Airbrake).not_to have_received(:notify)
132
+ expect(Airbrake[:default]).to have_received(:build_notice)
133
+ expect(Airbrake[:default]).not_to have_received(:notify)
134
134
  end
135
135
  end
136
136
  end
@@ -0,0 +1,70 @@
1
+ require 'spec_helper'
2
+ require 'airbrake/shoryuken/error_handler'
3
+
4
+ RSpec.describe Airbrake::Shoryuken::ErrorHandler do
5
+ let(:error) { AirbrakeTestError.new('shoryuken error') }
6
+ let(:body) { { message: 'message' } }
7
+ let(:queue) { 'foo_queue' }
8
+ let(:worker) do
9
+ Class.new do
10
+ def self.to_s
11
+ 'FooWorker'
12
+ end
13
+ end.new
14
+ end
15
+ let(:endpoint) do
16
+ 'https://airbrake.io/api/v3/projects/113743/notices?key=fd04e13d806a90f96614ad8e529b2822'
17
+ end
18
+
19
+ def wait_for_a_request_with_body(body)
20
+ wait_for(a_request(:post, endpoint).with(body: body)).to have_been_made.once
21
+ end
22
+
23
+ before do
24
+ stub_request(:post, endpoint).to_return(status: 201, body: '{}')
25
+ end
26
+
27
+ context "when there's an error" do
28
+ it 'notifies' do
29
+ expect do
30
+ subject.call(worker, queue, nil, body) { raise error }
31
+ end.to raise_error(error)
32
+
33
+ wait_for_a_request_with_body(/"message":"shoryuken\serror"/)
34
+ wait_for_a_request_with_body(/"params":{.*"queue":"#{queue}"/)
35
+ wait_for_a_request_with_body(/"params":{.*"body":\{"message":"message"\}/)
36
+ wait_for_a_request_with_body(/"component":"shoryuken","action":"FooWorker"/)
37
+ end
38
+
39
+ context "and it's a batch" do
40
+ let(:body) { [{ message1: 'message1' }, { message2: 'message2' }] }
41
+
42
+ it 'notifies' do
43
+ expect do
44
+ subject.call(worker, queue, nil, body) { raise error }
45
+ end.to raise_error(error)
46
+
47
+ wait_for_a_request_with_body(/"message":"shoryuken\serror"/)
48
+ wait_for_a_request_with_body(/"params":{.*"queue":"#{queue}"/)
49
+ wait_for_a_request_with_body(
50
+ /"params":{.*"batch":\[\{"message1":"message1"\},\{"message2":"message2"\}\]/
51
+ )
52
+ wait_for_a_request_with_body(/"component":"shoryuken","action":"FooWorker"/)
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'when Airbrake is not configured' do
58
+ it 'returns nil' do
59
+ allow(Airbrake).to receive(:build_notice).and_return(nil)
60
+ allow(Airbrake).to receive(:notify)
61
+
62
+ expect do
63
+ subject.call(worker, queue, nil, body) { raise error }
64
+ end.to raise_error(error)
65
+
66
+ expect(Airbrake).to have_received(:build_notice)
67
+ expect(Airbrake).not_to have_received(:notify)
68
+ end
69
+ end
70
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: airbrake
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.7.1
4
+ version: 5.8.0.rc.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: 2017-02-10 00:00:00.000000000 Z
11
+ date: 2017-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake-ruby
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '1.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '1.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -187,8 +187,8 @@ description: |
187
187
  determine the root cause.
188
188
 
189
189
  Additionally, this gem includes integrations with such popular libraries and
190
- frameworks as Rails, Sinatra, Resque, Sidekiq, Delayed Job, ActiveJob and many
191
- more.
190
+ frameworks as Rails, Sinatra, Resque, Sidekiq, Delayed Job, Shoryuken,
191
+ ActiveJob and many more.
192
192
  email: support@airbrake.io
193
193
  executables: []
194
194
  extensions: []
@@ -197,6 +197,7 @@ files:
197
197
  - lib/airbrake.rb
198
198
  - lib/airbrake/capistrano/tasks.rb
199
199
  - lib/airbrake/delayed_job/plugin.rb
200
+ - lib/airbrake/logger/logger_ext.rb
200
201
  - lib/airbrake/rack/context_filter.rb
201
202
  - lib/airbrake/rack/http_headers_filter.rb
202
203
  - lib/airbrake/rack/http_params_filter.rb
@@ -211,6 +212,7 @@ files:
211
212
  - lib/airbrake/rake/task_ext.rb
212
213
  - lib/airbrake/rake/tasks.rb
213
214
  - lib/airbrake/resque/failure.rb
215
+ - lib/airbrake/shoryuken/error_handler.rb
214
216
  - lib/airbrake/sidekiq/error_handler.rb
215
217
  - lib/airbrake/version.rb
216
218
  - lib/generators/airbrake_generator.rb
@@ -233,6 +235,7 @@ files:
233
235
  - spec/integration/sinatra/sinatra_spec.rb
234
236
  - spec/spec_helper.rb
235
237
  - spec/unit/airbrake_spec.rb
238
+ - spec/unit/logger/logger_ext_spec.rb
236
239
  - spec/unit/rack/context_filter_spec.rb
237
240
  - spec/unit/rack/http_headers_filter_spec.rb
238
241
  - spec/unit/rack/http_params_filter_spec.rb
@@ -241,6 +244,7 @@ files:
241
244
  - spec/unit/rack/session_filter_spec.rb
242
245
  - spec/unit/rack/user_spec.rb
243
246
  - spec/unit/rake/tasks_spec.rb
247
+ - spec/unit/shoryuken/error_handler_spec.rb
244
248
  - spec/unit/sidekiq/error_handler_spec.rb
245
249
  homepage: https://airbrake.io
246
250
  licenses:
@@ -257,9 +261,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
261
  version: '2.0'
258
262
  required_rubygems_version: !ruby/object:Gem::Requirement
259
263
  requirements:
260
- - - ">="
264
+ - - ">"
261
265
  - !ruby/object:Gem::Version
262
- version: '0'
266
+ version: 1.3.1
263
267
  requirements: []
264
268
  rubyforge_project:
265
269
  rubygems_version: 2.6.8
@@ -286,6 +290,7 @@ test_files:
286
290
  - spec/integration/sinatra/sinatra_spec.rb
287
291
  - spec/spec_helper.rb
288
292
  - spec/unit/airbrake_spec.rb
293
+ - spec/unit/logger/logger_ext_spec.rb
289
294
  - spec/unit/rack/context_filter_spec.rb
290
295
  - spec/unit/rack/http_headers_filter_spec.rb
291
296
  - spec/unit/rack/http_params_filter_spec.rb
@@ -294,4 +299,5 @@ test_files:
294
299
  - spec/unit/rack/session_filter_spec.rb
295
300
  - spec/unit/rack/user_spec.rb
296
301
  - spec/unit/rake/tasks_spec.rb
302
+ - spec/unit/shoryuken/error_handler_spec.rb
297
303
  - spec/unit/sidekiq/error_handler_spec.rb