airbrake 9.3.0 → 9.4.4

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: f0a71f9f79da2a5989445a300bebe3d9025df839
4
- data.tar.gz: 177632611970f6791ed686d3344df1eef7923010
3
+ metadata.gz: 645e4f963a8955c17a652cf468917e2ae514f849
4
+ data.tar.gz: 4f383442884699b67bd81943fd1c64cb527eb2d1
5
5
  SHA512:
6
- metadata.gz: 978eef94355d7bc09429086301983dfabb87426e7c54d0bb2044ef19ebcf3c39c1fae79f9e2954e718013ce7071c13a16005294b9ce48c47ff4e7fbf1aba2719
7
- data.tar.gz: c1006e0378f3f3b195362a9ca172359a3e131eae8de3e31cbaa017be6b7a8dc43dc58e3bb2ec4ca88b28cebab9f38bd9518a4b8a2f8e19c30340760c732124fa
6
+ metadata.gz: dab6ccce21fc171ef09f1d3e103ca6a02e943f997d17731da3d752ffcc789f46647789b189b827a26daace21683edc9dc6d3ada9dfebff3e869f5881d945ec5f
7
+ data.tar.gz: 3f2582844fd96b45c1e378a30b5950e32b05393630c2b716e15ffe49c244321e42f1db0646c3d3bf2a315efa09c07d8d16a3a72064c1a8f6c57be36200e09dbd
@@ -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.performance_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,26 +8,36 @@ module Airbrake
8
8
  Route = Struct.new(:path, :controller, :action)
9
9
 
10
10
  def routes
11
- @routes ||= [*app_routes, *engine_routes].map do |route|
12
- Route.new(
13
- route.path.spec.to_s,
14
- route.defaults[:controller],
15
- route.defaults[:action]
16
- )
11
+ @routes ||= app_routes.merge(engine_routes).flat_map do |(engine_name, routes)|
12
+ routes.map { |rails_route| build_route(engine_name, rails_route) }
17
13
  end
18
14
  end
19
15
 
20
16
  private
21
17
 
22
18
  def app_routes
23
- ::Rails.application.routes.routes.routes
19
+ # Engine name is nil because this is default (non-engine) routes.
20
+ { nil => ::Rails.application.routes.routes.routes }
24
21
  end
25
22
 
26
23
  def engine_routes
27
- ::Rails::Engine.subclasses.flat_map do |engine|
28
- engine.routes.routes.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
29
28
  end
30
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
31
41
  end
32
42
  end
33
43
  end
@@ -8,6 +8,8 @@ module Airbrake
8
8
  # @see https://github.com/rails/rails/issues/8987
9
9
  HTML_RESPONSE_WILDCARD = "*/*".freeze
10
10
 
11
+ include Airbrake::Loggable
12
+
11
13
  def initialize(*args)
12
14
  @event = ActiveSupport::Notifications::Event.new(*args)
13
15
  end
@@ -64,7 +66,13 @@ module Airbrake
64
66
  return status
65
67
  end
66
68
 
67
- 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
68
76
  end
69
77
 
70
78
  def duration
@@ -0,0 +1,141 @@
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) 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
138
+ end
139
+ end
140
+ end
141
+ end
@@ -13,6 +13,10 @@ module Airbrake
13
13
  DEFAULT_MAX_RETRY_ATTEMPTS = ::Sidekiq::JobRetry::DEFAULT_MAX_RETRY_ATTEMPTS
14
14
  end
15
15
 
16
+ def initialize(max_retries: nil)
17
+ @max_retries = max_retries
18
+ end
19
+
16
20
  def call(notice)
17
21
  job = notice[:params][:job]
18
22
 
@@ -30,7 +34,9 @@ module Airbrake
30
34
  end
31
35
 
32
36
  def max_attempts_for(job)
33
- if job['retry'].is_a?(Integer)
37
+ if @max_retries
38
+ @max_retries
39
+ elsif job['retry'].is_a?(Integer)
34
40
  job['retry']
35
41
  else
36
42
  max_retries
@@ -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.3.0'.freeze
4
+ AIRBRAKE_VERSION = '9.4.4'.freeze
5
5
  end
@@ -33,7 +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 = Rails.logger
36
+ c.logger = Airbrake::Rails.logger
37
37
 
38
38
  # Configures the environment the application is running in. Helps the Airbrake
39
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.3.0
4
+ version: 9.4.4
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-06-25 00:00:00.000000000 Z
11
+ date: 2019-09-18 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.5'
19
+ version: '4.6'
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.5'
26
+ version: '4.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -362,6 +362,7 @@ files:
362
362
  - lib/airbrake/rails/http.rb
363
363
  - lib/airbrake/rails/http_client.rb
364
364
  - lib/airbrake/rails/net_http.rb
365
+ - lib/airbrake/rails/railtie.rb
365
366
  - lib/airbrake/rails/typhoeus.rb
366
367
  - lib/airbrake/rake.rb
367
368
  - lib/airbrake/rake/tasks.rb
@@ -393,7 +394,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
393
394
  version: '0'
394
395
  requirements: []
395
396
  rubyforge_project:
396
- rubygems_version: 2.6.13
397
+ rubygems_version: 2.6.14.4
397
398
  signing_key:
398
399
  specification_version: 4
399
400
  summary: Airbrake is an online tool that provides robust exception tracking in any