airbrake 9.4.2 → 9.5.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9b1a464954b87f553c38390071a1303fdceb5685
4
- data.tar.gz: '0783aa316473e43d0f71a9962e0f8fac89cc1092'
2
+ SHA256:
3
+ metadata.gz: 4b5f9ef24127cd1a044a2959d8c90efd26e39db56e85ade6708340fc66009e36
4
+ data.tar.gz: 4e79c36be0244afaf4e9716b1d6d7b195cecf3b35bcd0ecfd95afaa426c02c69
5
5
  SHA512:
6
- metadata.gz: 4b10df6a1026885ad9770e6b9e594575356cd0c2d0dbd15aa775ab0ac67c6a079749bf2dbcacce5405ba5cc341481b0ef84a172e6654a3db893476b2326466ee
7
- data.tar.gz: 5426af26c8efde7f68b519e3ad7b151291b897fa8d6503c408b0e6c8bcca699554e80e7319ee7afb908a3fd2fd1390d2d59f31f78e1dfe04043d8eb8a26633de
6
+ metadata.gz: 9f8a4e8a07779cee46cb1b7d308db3d97bd9f1008aa4082966dbe0fffc8a043cf78439a7ad8b762887369ce37f1d245b70f9df73a899a1ccfd1b0880854e60bf
7
+ data.tar.gz: cf80d00213697bf952a3fa6c20a0cdd936381ced3005dccdefed28d4de912f243390e8916f571a3fbc234766bdfd7b8656cdf143010c14b0d7ef5b06372e51a2
@@ -14,7 +14,7 @@ module Airbrake
14
14
 
15
15
  notice[:context][:route] =
16
16
  if action_dispatch_request?(request)
17
- rails_route(request)
17
+ Airbrake::Rails::App.recognize_route(request)
18
18
  elsif sinatra_request?(request)
19
19
  sinatra_route(request)
20
20
  end
@@ -22,19 +22,6 @@ module Airbrake
22
22
 
23
23
  private
24
24
 
25
- def rails_route(request)
26
- ::Rails.application.routes.router.recognize(request) do |route, _parameters|
27
- # Rails can recognize multiple routes for the given request. For
28
- # example, if we visit /users/2/edit, then Rails sees these routes:
29
- # * "/users/:id/edit(.:format)"
30
- # * "/"
31
- #
32
- # We return the first route as, what it seems, the most optimal
33
- # approach.
34
- return route.path.spec.to_s
35
- end
36
- end
37
-
38
25
  def sinatra_route(request)
39
26
  return unless (route = request.env['sinatra.route'])
40
27
  route.split(' ').drop(1).join(' ')
@@ -26,7 +26,11 @@ module Airbrake
26
26
  controller = rack_env['action_controller.instance']
27
27
  return unless controller.respond_to?(:current_user, true)
28
28
  return unless [-1, 0].include?(controller.method(:current_user).arity)
29
- controller.__send__(:current_user)
29
+ begin
30
+ controller.__send__(:current_user)
31
+ rescue Exception => _e # rubocop:disable Lint/RescueException
32
+ nil
33
+ end
30
34
  end
31
35
  private_class_method :try_current_user
32
36
 
@@ -1,140 +1,19 @@
1
+ require 'airbrake/rails/railtie'
2
+
1
3
  module Airbrake
4
+ # Rails namespace holds all Rails-related functionality.
2
5
  module Rails
3
- # This railtie works for any Rails application that supports railties (Rails
4
- # 3.2+ apps). It makes Airbrake Ruby work with Rails and report errors
5
- # occurring in the application automatically.
6
- class Railtie < ::Rails::Railtie
7
- initializer('airbrake.middleware') do |app|
8
- # Since Rails 3.2 the ActionDispatch::DebugExceptions middleware is
9
- # responsible for logging exceptions and showing a debugging page in
10
- # case the request is local. We want to insert our middleware after
11
- # DebugExceptions, so we don't notify Airbrake about local requests.
12
-
13
- if ::Rails.version.to_i >= 5
14
- # Avoid the warning about deprecated strings.
15
- # Insert after DebugExceptions, since ConnectionManagement doesn't
16
- # exist in Rails 5 anymore.
17
- app.config.middleware.insert_after(
18
- ActionDispatch::DebugExceptions,
19
- Airbrake::Rack::Middleware
20
- )
21
- elsif defined?(::ActiveRecord::ConnectionAdapters::ConnectionManagement)
22
- # Insert after ConnectionManagement to avoid DB connection leakage:
23
- # https://github.com/airbrake/airbrake/pull/568
24
- app.config.middleware.insert_after(
25
- ::ActiveRecord::ConnectionAdapters::ConnectionManagement,
26
- 'Airbrake::Rack::Middleware'
27
- )
28
- else
29
- # Insert after DebugExceptions for apps without ActiveRecord.
30
- app.config.middleware.insert_after(
31
- ActionDispatch::DebugExceptions,
32
- 'Airbrake::Rack::Middleware'
33
- )
34
- end
35
- end
36
-
37
- rake_tasks do
38
- # Report exceptions occurring in Rake tasks.
39
- require 'airbrake/rake'
40
-
41
- # Defines tasks such as `airbrake:test` & `airbrake:deploy`.
42
- require 'airbrake/rake/tasks'
43
- end
44
-
45
- # rubocop:disable Metrics/BlockLength
46
- initializer('airbrake.action_controller') do
47
- ActiveSupport.on_load(:action_controller) do
48
- # Patches ActionController with methods that allow us to retrieve
49
- # interesting request data. Appends that information to notices.
50
- require 'airbrake/rails/action_controller'
51
- include Airbrake::Rails::ActionController
52
-
53
- if Airbrake::Config.instance.performance_stats
54
- # Cache route information for the duration of the request.
55
- require 'airbrake/rails/action_controller_route_subscriber'
56
- ActiveSupport::Notifications.subscribe(
57
- 'start_processing.action_controller',
58
- Airbrake::Rails::ActionControllerRouteSubscriber.new
59
- )
60
-
61
- # Send route stats.
62
- require 'airbrake/rails/action_controller_notify_subscriber'
63
- ActiveSupport::Notifications.subscribe(
64
- 'process_action.action_controller',
65
- Airbrake::Rails::ActionControllerNotifySubscriber.new
66
- )
67
-
68
- # Send performance breakdown: where a request spends its time.
69
- require 'airbrake/rails/action_controller_performance_breakdown_subscriber'
70
- ActiveSupport::Notifications.subscribe(
71
- 'process_action.action_controller',
72
- Airbrake::Rails::ActionControllerPerformanceBreakdownSubscriber.new
73
- )
74
-
75
- require 'airbrake/rails/net_http' if defined?(Net) && defined?(Net::HTTP)
76
-
77
- if defined?(Curl) && defined?(Curl::CURB_VERSION)
78
- require 'airbrake/rails/curb'
79
- end
80
-
81
- require 'airbrake/rails/http' if defined?(HTTP) && defined?(HTTP::Client)
82
- require 'airbrake/rails/http_client' if defined?(HTTPClient)
83
- require 'airbrake/rails/typhoeus' if defined?(Typhoeus)
84
-
85
- if defined?(Excon)
86
- require 'airbrake/rails/excon_subscriber'
87
- ActiveSupport::Notifications.subscribe(/excon/, Airbrake::Rails::Excon.new)
88
- ::Excon.defaults[:instrumentor] = ActiveSupport::Notifications
89
- end
90
- end
91
- end
92
- end
93
- # rubocop:enable Metrics/BlockLength
94
-
95
- initializer('airbrake.active_record') do
96
- ActiveSupport.on_load(:active_record) do
97
- # Reports exceptions occurring in some bugged ActiveRecord callbacks.
98
- # Applicable only to the versions of Rails lower than 4.2.
99
- require 'airbrake/rails/active_record'
100
- include Airbrake::Rails::ActiveRecord
101
-
102
- if defined?(ActiveRecord) && Airbrake::Config.instance.query_stats
103
- # Send SQL queries.
104
- require 'airbrake/rails/active_record_subscriber'
105
- ActiveSupport::Notifications.subscribe(
106
- 'sql.active_record', Airbrake::Rails::ActiveRecordSubscriber.new
107
- )
108
-
109
- # Filter out parameters from SQL body.
110
- Airbrake.add_performance_filter(
111
- Airbrake::Filters::SqlFilter.new(
112
- ::ActiveRecord::Base.connection_config[:adapter]
113
- )
114
- )
115
- end
116
- end
117
- end
118
-
119
- initializer('airbrake.active_job') do
120
- ActiveSupport.on_load(:active_job) do
121
- # Reports exceptions occurring in ActiveJob jobs.
122
- require 'airbrake/rails/active_job'
123
- include Airbrake::Rails::ActiveJob
124
- end
125
- end
126
-
127
- initializer('airbrake.action_cable') do
128
- ActiveSupport.on_load(:action_cable) do
129
- # Reports exceptions occurring in ActionCable connections.
130
- require 'airbrake/rails/action_cable'
131
- end
132
- end
133
-
134
- runner do
135
- at_exit do
136
- Airbrake.notify_sync($ERROR_INFO) if $ERROR_INFO
137
- end
6
+ def self.logger
7
+ if ENV['RAILS_LOG_TO_STDOUT'].present?
8
+ Logger.new(STDOUT, level: ::Rails.logger.level)
9
+ else
10
+ Logger.new(
11
+ ::Rails.root.join('log', 'airbrake.log'),
12
+
13
+ # Rails.logger is not set in some Rake tasks such as
14
+ # 'airbrake:deploy'. In this case we use a sensible fallback.
15
+ level: (::Rails.logger ? ::Rails.logger.level : Logger::ERROR)
16
+ )
138
17
  end
139
18
  end
140
19
  end
@@ -10,17 +10,17 @@ module Airbrake
10
10
  # A helper method for sending notices to Airbrake *asynchronously*.
11
11
  # Attaches information from the Rack env.
12
12
  # @see Airbrake#notify, #notify_airbrake_sync
13
- def notify_airbrake(exception, params = {})
13
+ def notify_airbrake(exception, params = {}, &block)
14
14
  return unless (notice = build_notice(exception, params))
15
- Airbrake.notify(notice, params)
15
+ Airbrake.notify(notice, params, &block)
16
16
  end
17
17
 
18
18
  # A helper method for sending notices to Airbrake *synchronously*.
19
19
  # Attaches information from the Rack env.
20
20
  # @see Airbrake#notify_sync, #notify_airbrake
21
- def notify_airbrake_sync(exception, params = {})
21
+ def notify_airbrake_sync(exception, params = {}, &block)
22
22
  return unless (notice = build_notice(exception, params))
23
- Airbrake.notify_sync(notice, params)
23
+ Airbrake.notify_sync(notice, params, &block)
24
24
  end
25
25
 
26
26
  # @param [Exception] exception
@@ -3,6 +3,12 @@ require 'airbrake/rails/app'
3
3
 
4
4
  module Airbrake
5
5
  module Rails
6
+ # @return [String]
7
+ CONTROLLER_KEY = 'controller'.freeze
8
+
9
+ # @return [String]
10
+ ACTION_KEY = 'action'.freeze
11
+
6
12
  # ActionControllerRouteSubscriber sends route stat information, including
7
13
  # performance data.
8
14
  #
@@ -17,24 +23,17 @@ module Airbrake
17
23
  return unless (routes = Airbrake::Rack::RequestStore[:routes])
18
24
 
19
25
  event = Airbrake::Rails::Event.new(*args)
20
- route = find_route(event.params)
26
+ route = Airbrake::Rails::App.recognize_route(
27
+ Airbrake::Rack::RequestStore[:request]
28
+ )
21
29
  return unless route
22
30
 
23
- routes[route.path] = {
31
+ routes[route] = {
24
32
  method: event.method,
25
33
  response_type: event.response_type,
26
34
  groups: {}
27
35
  }
28
36
  end
29
-
30
- private
31
-
32
- def find_route(params)
33
- @app.routes.find do |route|
34
- route.controller == params['controller'] &&
35
- route.action == params['action']
36
- end
37
- end
38
37
  end
39
38
  end
40
39
  end
@@ -7,6 +7,19 @@ module Airbrake
7
7
  class App
8
8
  Route = Struct.new(:path, :controller, :action)
9
9
 
10
+ def self.recognize_route(request)
11
+ ::Rails.application.routes.router.recognize(request) do |route, _parameters|
12
+ # Rails can recognize multiple routes for the given request. For
13
+ # example, if we visit /users/2/edit, then Rails sees these routes:
14
+ # * "/users/:id/edit(.:format)"
15
+ # * "/"
16
+ #
17
+ # We return the first route as, what it seems, the most optimal
18
+ # approach.
19
+ return route.path.spec.to_s
20
+ end
21
+ end
22
+
10
23
  def routes
11
24
  @routes ||= app_routes.merge(engine_routes).flat_map do |(engine_name, routes)|
12
25
  routes.map { |rails_route| build_route(engine_name, rails_route) }
@@ -66,11 +66,13 @@ module Airbrake
66
66
  return status
67
67
  end
68
68
 
69
- logger.error do
70
- "#{Airbrake::LOG_LABEL} unknown status code for: #{@event.payload}"
71
- end
72
-
73
- 0
69
+ # The ActiveSupport event doesn't have status only in two cases:
70
+ # - an exception was thrown
71
+ # - unauthorized access
72
+ # We have already handled the exception so what's left is unauthorized
73
+ # access. There's no way to know for sure it's unauthorized access, so
74
+ # we are rather optimistic here.
75
+ 401
74
76
  end
75
77
 
76
78
  def duration
@@ -0,0 +1,144 @@
1
+ module Airbrake
2
+ module Rails
3
+ # This railtie works for any Rails application that supports railties (Rails
4
+ # 3.2+ apps). It makes Airbrake Ruby work with Rails and report errors
5
+ # occurring in the application automatically.
6
+ class Railtie < ::Rails::Railtie
7
+ initializer('airbrake.middleware') do |app|
8
+ # Since Rails 3.2 the ActionDispatch::DebugExceptions middleware is
9
+ # responsible for logging exceptions and showing a debugging page in
10
+ # case the request is local. We want to insert our middleware after
11
+ # DebugExceptions, so we don't notify Airbrake about local requests.
12
+
13
+ if ::Rails.version.to_i >= 5
14
+ # Avoid the warning about deprecated strings.
15
+ # Insert after DebugExceptions, since ConnectionManagement doesn't
16
+ # exist in Rails 5 anymore.
17
+ app.config.middleware.insert_after(
18
+ ActionDispatch::DebugExceptions,
19
+ Airbrake::Rack::Middleware
20
+ )
21
+ elsif defined?(::ActiveRecord::ConnectionAdapters::ConnectionManagement)
22
+ # Insert after ConnectionManagement to avoid DB connection leakage:
23
+ # https://github.com/airbrake/airbrake/pull/568
24
+ app.config.middleware.insert_after(
25
+ ::ActiveRecord::ConnectionAdapters::ConnectionManagement,
26
+ 'Airbrake::Rack::Middleware'
27
+ )
28
+ else
29
+ # Insert after DebugExceptions for apps without ActiveRecord.
30
+ app.config.middleware.insert_after(
31
+ ActionDispatch::DebugExceptions,
32
+ 'Airbrake::Rack::Middleware'
33
+ )
34
+ end
35
+ end
36
+
37
+ rake_tasks do
38
+ # Report exceptions occurring in Rake tasks.
39
+ require 'airbrake/rake'
40
+
41
+ # Defines tasks such as `airbrake:test` & `airbrake:deploy`.
42
+ require 'airbrake/rake/tasks'
43
+ end
44
+
45
+ # rubocop:disable Metrics/BlockLength
46
+ initializer('airbrake.action_controller') do
47
+ ActiveSupport.on_load(:action_controller, run_once: true) do
48
+ # Patches ActionController with methods that allow us to retrieve
49
+ # interesting request data. Appends that information to notices.
50
+ require 'airbrake/rails/action_controller'
51
+ include Airbrake::Rails::ActionController
52
+
53
+ if Airbrake::Config.instance.performance_stats
54
+ # Cache route information for the duration of the request.
55
+ require 'airbrake/rails/action_controller_route_subscriber'
56
+ ActiveSupport::Notifications.subscribe(
57
+ 'start_processing.action_controller',
58
+ Airbrake::Rails::ActionControllerRouteSubscriber.new
59
+ )
60
+
61
+ # Send route stats.
62
+ require 'airbrake/rails/action_controller_notify_subscriber'
63
+ ActiveSupport::Notifications.subscribe(
64
+ 'process_action.action_controller',
65
+ Airbrake::Rails::ActionControllerNotifySubscriber.new
66
+ )
67
+
68
+ # Send performance breakdown: where a request spends its time.
69
+ require 'airbrake/rails/action_controller_performance_breakdown_subscriber'
70
+ ActiveSupport::Notifications.subscribe(
71
+ 'process_action.action_controller',
72
+ Airbrake::Rails::ActionControllerPerformanceBreakdownSubscriber.new
73
+ )
74
+
75
+ require 'airbrake/rails/net_http' if defined?(Net) && defined?(Net::HTTP)
76
+
77
+ if defined?(Curl) && defined?(Curl::CURB_VERSION)
78
+ require 'airbrake/rails/curb'
79
+ end
80
+
81
+ require 'airbrake/rails/http' if defined?(HTTP) && defined?(HTTP::Client)
82
+ require 'airbrake/rails/http_client' if defined?(HTTPClient)
83
+ require 'airbrake/rails/typhoeus' if defined?(Typhoeus)
84
+
85
+ if defined?(Excon)
86
+ require 'airbrake/rails/excon_subscriber'
87
+ ActiveSupport::Notifications.subscribe(/excon/, Airbrake::Rails::Excon.new)
88
+ ::Excon.defaults[:instrumentor] = ActiveSupport::Notifications
89
+ end
90
+ end
91
+ end
92
+ end
93
+ # rubocop:enable Metrics/BlockLength
94
+
95
+ initializer('airbrake.active_record') do
96
+ ActiveSupport.on_load(:active_record, run_once: true) do
97
+ # Reports exceptions occurring in some bugged ActiveRecord callbacks.
98
+ # Applicable only to the versions of Rails lower than 4.2.
99
+ if defined?(::Rails) &&
100
+ Gem::Version.new(::Rails.version) <= Gem::Version.new('4.2')
101
+ require 'airbrake/rails/active_record'
102
+ include Airbrake::Rails::ActiveRecord
103
+ end
104
+
105
+ if defined?(ActiveRecord) && Airbrake::Config.instance.query_stats
106
+ # Send SQL queries.
107
+ require 'airbrake/rails/active_record_subscriber'
108
+ ActiveSupport::Notifications.subscribe(
109
+ 'sql.active_record', Airbrake::Rails::ActiveRecordSubscriber.new
110
+ )
111
+
112
+ # Filter out parameters from SQL body.
113
+ Airbrake.add_performance_filter(
114
+ Airbrake::Filters::SqlFilter.new(
115
+ ::ActiveRecord::Base.connection_config[:adapter]
116
+ )
117
+ )
118
+ end
119
+ end
120
+ end
121
+
122
+ initializer('airbrake.active_job') do
123
+ ActiveSupport.on_load(:active_job, run_once: true) do
124
+ # Reports exceptions occurring in ActiveJob jobs.
125
+ require 'airbrake/rails/active_job'
126
+ include Airbrake::Rails::ActiveJob
127
+ end
128
+ end
129
+
130
+ initializer('airbrake.action_cable') do
131
+ ActiveSupport.on_load(:action_cable, run_once: true) do
132
+ # Reports exceptions occurring in ActionCable connections.
133
+ require 'airbrake/rails/action_cable'
134
+ end
135
+ end
136
+
137
+ runner do
138
+ at_exit do
139
+ Airbrake.notify_sync($ERROR_INFO) if $ERROR_INFO
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
@@ -1,5 +1,5 @@
1
1
  # We use Semantic Versioning v2.0.0
2
2
  # More information: http://semver.org/
3
3
  module Airbrake
4
- AIRBRAKE_VERSION = '9.4.2'.freeze
4
+ AIRBRAKE_VERSION = '9.5.1'.freeze
5
5
  end
@@ -33,15 +33,7 @@ Airbrake.configure do |c|
33
33
  # By default, Airbrake Ruby outputs to STDOUT. In Rails apps it makes sense to
34
34
  # use the Rails' logger.
35
35
  # https://github.com/airbrake/airbrake-ruby#logger
36
- c.logger =
37
- if ENV['RAILS_LOG_TO_STDOUT'].present?
38
- Logger.new(STDOUT, level: Rails.logger.level)
39
- else
40
- Logger.new(
41
- Rails.root.join('log', 'airbrake.log'),
42
- level: Rails.logger.level
43
- )
44
- end
36
+ c.logger = Airbrake::Rails.logger
45
37
 
46
38
  # Configures the environment the application is running in. Helps the Airbrake
47
39
  # dashboard to distinguish between exceptions occurring in different
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: 9.4.2
4
+ version: 9.5.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-08-07 00:00:00.000000000 Z
11
+ date: 2019-11-25 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: '4.6'
19
+ version: '4.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: '4.6'
26
+ version: '4.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -226,6 +226,34 @@ dependencies:
226
226
  - - '='
227
227
  - !ruby/object:Gem::Version
228
228
  version: 1.13.0
229
+ - !ruby/object:Gem::Dependency
230
+ name: minitest
231
+ requirement: !ruby/object:Gem::Requirement
232
+ requirements:
233
+ - - '='
234
+ - !ruby/object:Gem::Version
235
+ version: 5.11.3
236
+ type: :development
237
+ prerelease: false
238
+ version_requirements: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - '='
241
+ - !ruby/object:Gem::Version
242
+ version: 5.11.3
243
+ - !ruby/object:Gem::Dependency
244
+ name: rack-cache
245
+ requirement: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - '='
248
+ - !ruby/object:Gem::Version
249
+ version: 1.9.0
250
+ type: :development
251
+ prerelease: false
252
+ version_requirements: !ruby/object:Gem::Requirement
253
+ requirements:
254
+ - - '='
255
+ - !ruby/object:Gem::Version
256
+ version: 1.9.0
229
257
  - !ruby/object:Gem::Dependency
230
258
  name: sidekiq
231
259
  requirement: !ruby/object:Gem::Requirement
@@ -362,6 +390,7 @@ files:
362
390
  - lib/airbrake/rails/http.rb
363
391
  - lib/airbrake/rails/http_client.rb
364
392
  - lib/airbrake/rails/net_http.rb
393
+ - lib/airbrake/rails/railtie.rb
365
394
  - lib/airbrake/rails/typhoeus.rb
366
395
  - lib/airbrake/rake.rb
367
396
  - lib/airbrake/rake/tasks.rb
@@ -393,7 +422,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
393
422
  version: '0'
394
423
  requirements: []
395
424
  rubyforge_project:
396
- rubygems_version: 2.6.14.4
425
+ rubygems_version: 2.7.6.2
397
426
  signing_key:
398
427
  specification_version: 4
399
428
  summary: Airbrake is an online tool that provides robust exception tracking in any