airbrake 9.4.3 → 9.5.2

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
- SHA1:
3
- metadata.gz: fe9037ca230b5a680582dff789221db846fd346e
4
- data.tar.gz: 6471b5f85ac64b3031aeca6c9f7d4a37a437496e
2
+ SHA256:
3
+ metadata.gz: 5e8ae1c646cf9107329a7413bd0654873c55b47a84a51c7c25d6c7655768c1fd
4
+ data.tar.gz: 516194657a9ceca56fd9843f39d4293a74ccee6db11f6ad084519924eb911b46
5
5
  SHA512:
6
- metadata.gz: 503a6f588f31ac85581e4b9906614941a8680f3b45ac7b7e1da5d115c3064e116debb15c55e5e68f9d4daf46f419804f90cb0a931b1d9eb8b5bfef644a8f2cd7
7
- data.tar.gz: ae3d0ebc69c627c5df4a69f83fb96ec9be1dfcd88e883adeacf63ea516f56f7623d78862666f8a1e92df278265b3c8454e9f33f0a0548dc49a4b20124471a653
6
+ metadata.gz: 75c112cdf4780dedae3ee51e1d83637f16c2cc1c76fb2cbc077ffa64ebb8dde3aeed4cb589ce3056975fda8f28e36f0dc4e7d212f554a0d413c4d0751bffe02a
7
+ data.tar.gz: 18e7c15a1630ff39730cb1b8c36f21ea333b2b12f202bbb75e0b82e4c3a4676df1c7b2fc4e8c779559c588b34ce8fc2338ef6992c487274e3254a72b47f09464
@@ -23,16 +23,8 @@ module Airbrake
23
23
  private
24
24
 
25
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
26
+ return unless (route = Airbrake::Rails::App.recognize_route(request))
27
+ route.path.spec.to_s
36
28
  end
37
29
 
38
30
  def sinatra_route(request)
@@ -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
@@ -8,31 +8,28 @@ module Airbrake
8
8
  #
9
9
  # @since v8.0.0
10
10
  class ActionControllerRouteSubscriber
11
- def initialize
12
- @app = Airbrake::Rails::App.new
13
- end
14
-
15
11
  def call(*args)
16
12
  # We don't track routeless events.
17
13
  return unless (routes = Airbrake::Rack::RequestStore[:routes])
18
14
 
19
15
  event = Airbrake::Rails::Event.new(*args)
20
- route = find_route(event.params)
16
+ route = Airbrake::Rails::App.recognize_route(
17
+ Airbrake::Rack::RequestStore[:request]
18
+ )
21
19
  return unless route
22
20
 
23
- routes[route.path] = {
21
+ routes[find_route_name(route)] = {
24
22
  method: event.method,
25
23
  response_type: event.response_type,
26
24
  groups: {}
27
25
  }
28
26
  end
29
27
 
30
- private
31
-
32
- def find_route(params)
33
- @app.routes.find do |route|
34
- route.controller == params['controller'] &&
35
- route.action == params['action']
28
+ def find_route_name(route)
29
+ if route.app.respond_to?(:app) && route.app.app.respond_to?(:engine_name)
30
+ "#{route.app.app.engine_name}##{route.path.spec}"
31
+ else
32
+ route.path.spec.to_s
36
33
  end
37
34
  end
38
35
  end
@@ -1,43 +1,22 @@
1
1
  module Airbrake
2
2
  module Rails
3
- # App is a wrapper around Rails.application and Rails::Engine.
3
+ # App is a wrapper around Rails.application.
4
4
  #
5
5
  # @since v9.0.3
6
6
  # @api private
7
7
  class App
8
- Route = Struct.new(:path, :controller, :action)
9
-
10
- def routes
11
- @routes ||= app_routes.merge(engine_routes).flat_map do |(engine_name, routes)|
12
- routes.map { |rails_route| build_route(engine_name, rails_route) }
8
+ def self.recognize_route(request)
9
+ ::Rails.application.routes.router.recognize(request) do |route, _params|
10
+ # Rails can recognize multiple routes for the given request. For
11
+ # example, if we visit /users/2/edit, then Rails sees these routes:
12
+ # * "/users/:id/edit(.:format)"
13
+ # * "/"
14
+ #
15
+ # We return the first route as, what it seems, the most optimal
16
+ # approach.
17
+ return route
13
18
  end
14
19
  end
15
-
16
- private
17
-
18
- def app_routes
19
- # Engine name is nil because this is default (non-engine) routes.
20
- { nil => ::Rails.application.routes.routes.routes }
21
- end
22
-
23
- def engine_routes
24
- ::Rails::Engine.subclasses.flat_map.with_object({}) do |engine, hash|
25
- next if (eng_routes = engine.routes.routes.routes).none?
26
-
27
- hash[engine.engine_name] = eng_routes
28
- end
29
- end
30
-
31
- def build_route(engine_name, rails_route)
32
- engine_prefix = engine_name
33
- engine_prefix += '#' if engine_prefix
34
-
35
- Route.new(
36
- "#{engine_prefix}#{rails_route.path.spec}",
37
- rails_route.defaults[:controller],
38
- rails_route.defaults[:action]
39
- )
40
- end
41
20
  end
42
21
  end
43
22
  end
@@ -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.3'.freeze
4
+ AIRBRAKE_VERSION = '9.5.2'.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.3
4
+ version: 9.5.2
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-08 00:00:00.000000000 Z
11
+ date: 2019-11-26 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