airbrake 9.2.1 → 9.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/airbrake/rack/middleware.rb +21 -13
  3. data/lib/airbrake/rails/action_controller_performance_breakdown_subscriber.rb +20 -2
  4. data/lib/airbrake/version.rb +1 -1
  5. metadata +5 -81
  6. data/spec/apps/rack/dummy_app.rb +0 -17
  7. data/spec/apps/rails/dummy_app.rb +0 -258
  8. data/spec/apps/rails/dummy_task.rake +0 -15
  9. data/spec/apps/rails/logs/32.log +0 -34094
  10. data/spec/apps/rails/logs/42.log +0 -1488
  11. data/spec/apps/rails/logs/52.log +0 -6321
  12. data/spec/apps/sinatra/sinatra_test_app.rb +0 -12
  13. data/spec/integration/rack/rack_spec.rb +0 -19
  14. data/spec/integration/rails/rails_spec.rb +0 -430
  15. data/spec/integration/rails/rake_spec.rb +0 -97
  16. data/spec/integration/shared_examples/rack_examples.rb +0 -110
  17. data/spec/integration/sinatra/sinatra_spec.rb +0 -30
  18. data/spec/spec_helper.rb +0 -105
  19. data/spec/support/matchers/a_notice_with.rb +0 -29
  20. data/spec/unit/logger_spec.rb +0 -125
  21. data/spec/unit/rack/context_filter_spec.rb +0 -90
  22. data/spec/unit/rack/http_headers_filter_spec.rb +0 -44
  23. data/spec/unit/rack/http_params_filter_spec.rb +0 -58
  24. data/spec/unit/rack/instrumentable_spec.rb +0 -105
  25. data/spec/unit/rack/middleware_spec.rb +0 -98
  26. data/spec/unit/rack/rack_spec.rb +0 -46
  27. data/spec/unit/rack/request_body_filter_spec.rb +0 -44
  28. data/spec/unit/rack/request_store_spec.rb +0 -36
  29. data/spec/unit/rack/route_filter_spec.rb +0 -52
  30. data/spec/unit/rack/session_filter_spec.rb +0 -44
  31. data/spec/unit/rack/user_filter_spec.rb +0 -30
  32. data/spec/unit/rack/user_spec.rb +0 -218
  33. data/spec/unit/rails/action_cable/notify_callback_spec.rb +0 -26
  34. data/spec/unit/rails/action_controller_notify_subscriber_spec.rb +0 -43
  35. data/spec/unit/rails/action_controller_performance_breakdown_subscriber_spec.rb +0 -63
  36. data/spec/unit/rails/action_controller_route_subscriber_spec.rb +0 -84
  37. data/spec/unit/rails/active_record_subscriber_spec.rb +0 -70
  38. data/spec/unit/rails/excon_spec.rb +0 -46
  39. data/spec/unit/rake/tasks_spec.rb +0 -70
  40. data/spec/unit/shoryuken_spec.rb +0 -55
  41. data/spec/unit/sidekiq/retryable_jobs_filter_spec.rb +0 -36
  42. data/spec/unit/sidekiq_spec.rb +0 -33
  43. data/spec/unit/sneakers_spec.rb +0 -83
@@ -1,12 +0,0 @@
1
- class SinatraTestApp < Sinatra::Base
2
- use Airbrake::Rack::Middleware
3
- use Warden::Manager
4
-
5
- get '/' do
6
- 'Hello from index'
7
- end
8
-
9
- get '/crash' do
10
- raise AirbrakeTestError
11
- end
12
- end
@@ -1,19 +0,0 @@
1
- require 'integration/shared_examples/rack_examples'
2
-
3
- RSpec.describe "Rack integration specs" do
4
- let(:app) { DummyApp }
5
-
6
- include_examples 'rack examples'
7
-
8
- describe "context payload" do
9
- before { stub_request(:post, endpoint).to_return(status: 200, body: '') }
10
-
11
- it "includes version" do
12
- get '/crash'
13
- sleep 2
14
-
15
- body = /"context":{.*"versions":{"rack_version":"\d\..+","rack_release":"\d\..+"}/
16
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made
17
- end
18
- end
19
- end
@@ -1,430 +0,0 @@
1
- require 'integration/shared_examples/rack_examples'
2
-
3
- RSpec.describe "Rails integration specs" do
4
- include Warden::Test::Helpers
5
-
6
- let(:app) { Rails.application }
7
-
8
- include_examples 'rack examples'
9
-
10
- if ::Rails.version.start_with?('5.')
11
- it "inserts the Airbrake Rack middleware after DebugExceptions" do
12
- middlewares = Rails.configuration.middleware.middlewares.map(&:inspect)
13
- own_idx = middlewares.index('Airbrake::Rack::Middleware')
14
-
15
- expect(middlewares[own_idx - 1]).to eq('ActionDispatch::DebugExceptions')
16
- end
17
- else
18
- it "inserts the Airbrake Rack middleware after ConnectionManagement" do
19
- middlewares = Rails.configuration.middleware.middlewares.map(&:inspect)
20
- own_idx = middlewares.index('Airbrake::Rack::Middleware')
21
-
22
- expect(middlewares[own_idx - 1])
23
- .to eq('ActiveRecord::ConnectionAdapters::ConnectionManagement')
24
- end
25
- end
26
-
27
- shared_examples "context payload content" do |route|
28
- let(:user) do
29
- OpenStruct.new(
30
- id: 1,
31
- email: 'qa@example.com',
32
- username: 'qa-dept'
33
- )
34
- end
35
-
36
- before do
37
- login_as(user)
38
- get(route, foo: :bar)
39
- sleep 2
40
- end
41
-
42
- it "includes component information" do
43
- body = /"context":{.*"component":"dummy".*}/
44
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made
45
- end
46
-
47
- it "includes action information" do
48
- body =
49
- case route
50
- when '/crash'
51
- /"context":{.*"action":"crash".*}/
52
- when '/notify_airbrake_helper'
53
- /"context":{.*"action":"notify_airbrake_helper".*}/
54
- when '/notify_airbrake_sync_helper'
55
- /"context":{.*"action":"notify_airbrake_sync_helper".*}/
56
- else
57
- raise 'Unknown route'
58
- end
59
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made
60
- end
61
-
62
- it "includes version" do
63
- body = /"context":{.*"versions":{"rails":"\d\./
64
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made
65
- end
66
-
67
- it "includes session" do
68
- body = /"context":{.*"session":{.*"session_id":"\w+".*}/
69
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made
70
- end
71
-
72
- it "includes params" do
73
- action = route[1..-1]
74
- body = /"context":{.*"params":{.*"controller":"dummy","action":"#{action}".*}/
75
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made
76
- end
77
-
78
- it "includes route" do
79
- body = /"context":{.*"route":"#{route}\(\.:format\)".*}/
80
- expect(a_request(:post, endpoint).with(body: body)).to have_been_made
81
- end
82
- end
83
-
84
- describe "context payload" do
85
- context "when exception reported through middleware" do
86
- include_examples('context payload content', '/crash')
87
- end
88
-
89
- context "when exception reported through the notify_airbrake helper" do
90
- include_examples('context payload content', '/notify_airbrake_helper')
91
- end
92
-
93
- context "when exception reported through the notify_airbrake_sync helper" do
94
- include_examples('context payload content', '/notify_airbrake_sync_helper')
95
- end
96
- end
97
-
98
- describe(
99
- "Active Record callbacks",
100
- skip: Gem::Version.new(Rails.version) < Gem::Version.new('5.1.0')
101
- ) do
102
- it "reports exceptions in after_commit callbacks" do
103
- expect(Airbrake).to receive(:notify).with(
104
- an_instance_of(AirbrakeTestError)
105
- ) do |exception|
106
- expect(exception.message).to eq('after_commit')
107
- end
108
-
109
- get '/active_record_after_commit'
110
- end
111
-
112
- it "reports exceptions in after_rollback callbacks" do
113
- expect(Airbrake).to receive(:notify).with(
114
- an_instance_of(AirbrakeTestError)
115
- ) do |exception|
116
- expect(exception.message).to eq('after_rollback')
117
- end
118
-
119
- get '/active_record_after_rollback'
120
- end
121
- end
122
-
123
- if Gem::Version.new(Rails.version) >= Gem::Version.new('4.2')
124
- describe "ActiveJob jobs" do
125
- it "reports exceptions occurring in ActiveJob workers" do
126
- expect(Airbrake).to receive(:notify)
127
- .with(an_instance_of(Airbrake::Notice)).at_least(:once)
128
-
129
- get '/active_job'
130
- sleep 2 # Wait for ActiveJob job exiting
131
- end
132
-
133
- context "when Airbrake is not configured" do
134
- before do
135
- # Make sure we don't call `build_notice` more than 1 time. Rack
136
- # integration will try to handle error 500 and we want to prevent
137
- # that: https://github.com/airbrake/airbrake/pull/583
138
- allow_any_instance_of(Airbrake::Rack::Middleware).to(
139
- receive(:notify_airbrake).and_return(nil)
140
- )
141
- end
142
-
143
- it "doesn't report errors" do
144
- expect(Airbrake).to receive(:notify).with(
145
- an_instance_of(Airbrake::Notice)
146
- ) { |notice|
147
- # TODO: this doesn't actually fail but prints a failure. Figure
148
- # out how to test properly.
149
- expect(notice[:errors].first[:message]).to eq('active_job error')
150
- }.at_least(:once)
151
-
152
- get '/active_job'
153
- sleep 2
154
- end
155
- end
156
- end
157
- end
158
-
159
- describe "Resque workers" do
160
- it "reports exceptions occurring in Resque workers" do
161
- expect(Airbrake).to receive(:notify_sync).with(
162
- anything,
163
- hash_including(
164
- 'class' => 'BingoWorker',
165
- 'args' => %w[bango bongo]
166
- )
167
- )
168
- with_resque { get '/resque' }
169
- end
170
- end
171
-
172
- describe "DelayedJob jobs" do
173
- it "reports exceptions occurring in DelayedJob jobs" do
174
- skip if Gem::Version.new(Rails.version) > Gem::Version.new('3.2.22.5')
175
-
176
- expect(Airbrake).to receive(:notify).with(
177
- anything,
178
- 'job' => hash_including(
179
- 'handler' => "--- !ruby/struct:BangoJob\nbingo: bingo\nbongo: bongo\n"
180
- )
181
- )
182
-
183
- get '/delayed_job'
184
- end
185
-
186
- it "reports exceptions occurring in DelayedJob jobs on Rails 4.2" do
187
- skip if Gem::Version.new(Rails.version) == Gem::Version.new('3.2.22.5')
188
-
189
- expect(Airbrake).to receive(:notify).with(
190
- anything,
191
- hash_including(
192
- 'handler' => "--- !ruby/struct:BangoJob\nbingo: bingo\nbongo: bongo\n"
193
- )
194
- )
195
-
196
- get '/delayed_job'
197
- end
198
- end
199
-
200
- describe "user extraction" do
201
- context "when Warden is not available but 'current_user' is defined" do
202
- let(:user) do
203
- OpenStruct.new(
204
- id: 1,
205
- email: 'qa@example.com',
206
- username: 'qa-dept'
207
- )
208
- end
209
-
210
- before do
211
- allow_message_expectations_on_nil
212
- allow(Warden::Proxy).to receive(:new).and_return(nil)
213
- # Mock on_request to make the test pass. Started failing in warden 1.2.8
214
- # due to: https://github.com/wardencommunity/warden/pull/162
215
- allow(nil).to receive(:on_request).and_return(nil)
216
- allow_any_instance_of(DummyController).to receive(:current_user) { user }
217
- end
218
-
219
- it "sends user info" do
220
- get '/crash'
221
- sleep 2
222
-
223
- body = /"user":{"id":"1","username":"qa-dept","email":"qa@example.com"}/
224
- wait_for(a_request(:post, endpoint).with(body: body)).to have_been_made
225
- end
226
- end
227
- end
228
-
229
- describe "request performance hook" do
230
- before { allow(Airbrake).to receive(:notify).and_return(nil) }
231
-
232
- it "notifies request" do
233
- expect(Airbrake).to receive(:notify_request).with(
234
- hash_including(
235
- route: '/crash(.:format)',
236
- method: 'GET'
237
- )
238
- )
239
- get '/crash'
240
- end
241
-
242
- it "defaults to 500 when status code for exception returns 0" do
243
- allow(ActionDispatch::ExceptionWrapper)
244
- .to receive(:status_code_for_exception).and_return(0)
245
-
246
- expect(Airbrake).to receive(:notify_request).with(
247
- hash_including(
248
- route: '/crash(.:format)',
249
- method: 'HEAD',
250
- status_code: 500
251
- )
252
- )
253
- head '/crash'
254
- end
255
- end
256
-
257
- describe "query performance hook" do
258
- before { allow(Airbrake).to receive(:notify).and_return(nil) }
259
-
260
- it "sends queries to Airbrake" do
261
- expect(Airbrake).to receive(:notify_query).with(
262
- hash_including(
263
- route: '/crash(.:format)',
264
- method: 'GET',
265
- func: 'call',
266
- file: 'lib/airbrake/rails/active_record_subscriber.rb',
267
- line: anything
268
- )
269
- ).at_least(:once)
270
-
271
- get '/crash'
272
- end
273
-
274
- context "when caller location cannot be found for a query" do
275
- before { allow(Kernel).to receive(:caller).and_return([]) }
276
-
277
- it "sends query to Airbrake without caller location" do
278
- expect(Airbrake).to receive(:notify_query).with(
279
- hash_including(
280
- route: '/crash(.:format)',
281
- method: 'GET',
282
- func: nil,
283
- file: nil,
284
- line: nil
285
- )
286
- ).at_least(:once)
287
-
288
- get '/crash'
289
- end
290
- end
291
- end
292
-
293
- describe "performance breakdown hook" do
294
- before { allow(Airbrake).to receive(:notify).and_return(nil) }
295
-
296
- it "sends performance breakdown info to Airbrake" do
297
- expect(Airbrake).to receive(:notify_performance_breakdown).with(
298
- hash_including(
299
- route: '/breakdown(.:format)',
300
- method: 'GET',
301
- response_type: :html,
302
- groups: hash_including(db: an_instance_of(Float))
303
- )
304
- ).at_least(:once)
305
-
306
- get '/breakdown'
307
- end
308
-
309
- context "when response format is */*" do
310
- it "normalizes it to :html" do
311
- expect(Airbrake).to receive(:notify_performance_breakdown)
312
- .with(hash_including(response_type: :html))
313
- get '/breakdown', {}, 'HTTP_ACCEPT' => '*/*'
314
- end
315
- end
316
-
317
- context "when db_runtime is nil" do
318
- it "omits the db group" do
319
- expect(Airbrake).to receive(:notify_performance_breakdown)
320
- .with(hash_including(groups: { view: be > 0 }))
321
- get '/breakdown_view_only'
322
- end
323
- end
324
-
325
- context "when an action performs a Net::HTTP request" do
326
- let!(:example_request) do
327
- stub_request(:get, 'http://example.com').to_return(body: '')
328
- end
329
-
330
- it "includes the http breakdown" do
331
- expect(Airbrake).to receive(:notify_performance_breakdown)
332
- .with(hash_including(groups: { view: be > 0, http: be > 0 }))
333
- get '/breakdown_http'
334
- expect(example_request).to have_been_made
335
- end
336
- end
337
-
338
- context "when an action performs a Curl request" do
339
- let!(:example_request) do
340
- stub_request(:get, 'http://example.com').to_return(body: '')
341
- end
342
-
343
- before { skip("JRuby doesn't support Curb") if Airbrake::JRUBY }
344
-
345
- it "includes the http breakdown" do
346
- expect(Airbrake).to receive(:notify_performance_breakdown)
347
- .with(hash_including(groups: { view: be > 0, http: be > 0 }))
348
- get '/breakdown_curl_http'
349
- expect(example_request).to have_been_made
350
- end
351
- end
352
-
353
- context "when an action performs a Curl::Easy request" do
354
- let!(:example_request) do
355
- stub_request(:get, 'http://example.com').to_return(body: '')
356
- end
357
-
358
- before { skip("JRuby doesn't support Curb") if Airbrake::JRUBY }
359
-
360
- it "includes the http breakdown" do
361
- expect(Airbrake).to receive(:notify_performance_breakdown)
362
- .with(hash_including(groups: { view: be > 0, http: be > 0 }))
363
- get '/breakdown_curl_http_easy'
364
- expect(example_request).to have_been_made
365
- end
366
- end
367
-
368
- context "when an action performs a Curl::Multi request" do
369
- before { skip("JRuby doesn't support Curb") if Airbrake::JRUBY }
370
-
371
- it "includes the http breakdown" do
372
- expect(Airbrake).to receive(:notify_performance_breakdown)
373
- .with(hash_including(groups: { view: be > 0, http: be > 0 }))
374
- get '/breakdown_curl_http_multi'
375
- end
376
- end
377
-
378
- context "when an action performs an Excon request" do
379
- let!(:example_request) do
380
- stub_request(:get, 'http://example.com').to_return(body: '')
381
- end
382
-
383
- it "includes the http breakdown" do
384
- expect(Airbrake).to receive(:notify_performance_breakdown)
385
- .with(hash_including(groups: { http: be > 0 }))
386
- get '/breakdown_excon'
387
- expect(example_request).to have_been_made
388
- end
389
- end
390
-
391
- context "when an action performs a HTTP.rb request" do
392
- let!(:example_request) do
393
- stub_request(:get, 'http://example.com').to_return(body: '')
394
- end
395
-
396
- it "includes the http breakdown" do
397
- expect(Airbrake).to receive(:notify_performance_breakdown)
398
- .with(hash_including(groups: { http: be > 0 }))
399
- get '/breakdown_http_rb'
400
- expect(example_request).to have_been_made
401
- end
402
- end
403
-
404
- context "when an action performs a HTTPClient request" do
405
- let!(:example_request) do
406
- stub_request(:get, 'http://example.com').to_return(body: '')
407
- end
408
-
409
- it "includes the http breakdown" do
410
- expect(Airbrake).to receive(:notify_performance_breakdown)
411
- .with(hash_including(groups: { http: be > 0 }))
412
- get '/breakdown_http_client'
413
- expect(example_request).to have_been_made
414
- end
415
- end
416
-
417
- context "when an action performs a Typhoeus request" do
418
- let!(:example_request) do
419
- stub_request(:get, 'http://example.com').to_return(body: '')
420
- end
421
-
422
- it "includes the http breakdown" do
423
- expect(Airbrake).to receive(:notify_performance_breakdown)
424
- .with(hash_including(groups: { http: be > 0 }))
425
- get '/breakdown_typhoeus'
426
- expect(example_request).to have_been_made
427
- end
428
- end
429
- end
430
- end