airbrake 13.0.0 → 13.0.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
2
  SHA256:
3
- metadata.gz: a07739c02f3e1221ca95e82f58fd79a36a94419144079db6eec8a935b5f8bfad
4
- data.tar.gz: 9e4da0976faf90b479903503fb00aa6f21b7bb469089c1795d6019ed5b001d4a
3
+ metadata.gz: 668e709e9a773bc589715b99f9843ce37c1af8b307551e718c7cbe9f00966398
4
+ data.tar.gz: 00637f796a64e51709bd2db34f3bc22845d264e21ca9938c1499571e3920025d
5
5
  SHA512:
6
- metadata.gz: 4954a38023b2bd13afeef26690701876ab90141e7f552a020ce32f6182a5352d1211bba9d7f9965ebafc0603f444c1caeb1d282ef15e291ccec10298a5504e84
7
- data.tar.gz: 9bcb90f9b3d621c2be1d3a653be9a434831f42399035af8eb57c8eac94c6f4c00d40d3bc2b8335794460b122277e0a9cee18cd44a57757ee492146188fc89054
6
+ metadata.gz: e21c16eb3577a99831676f048f7c6543694954eefe17b1115ca6796caab1d88f3fc1610474c69ba98b32f8aad661d5738091ed34442c1b37ec121d62b03ed5e0
7
+ data.tar.gz: 56677458f588058a4313e93ace216ac6475fb5d8c5d0bd0557e86105e0884296c55450d45930a7f2d91e95d6fe1be7d4a4b325937455fea6bc2d2d59568eda9a
@@ -21,7 +21,7 @@ module Airbrake
21
21
  RAILS_ENV=#{fetch(:rails_env, nil)} \
22
22
 
23
23
  bundle exec rake airbrake:deploy \
24
- USERNAME=#{Shellwords.shellescape(ENV['USER'] || ENV['USERNAME'])} \
24
+ USERNAME=#{Shellwords.shellescape(ENV.fetch('USER', nil) || ENV.fetch('USERNAME', nil))} \
25
25
  ENVIRONMENT=#{fetch(:airbrake_env, fetch(:rails_env, 'production'))} \
26
26
  REVISION=#{current_revision.strip} \
27
27
  REPOSITORY=#{repository} \
@@ -9,6 +9,10 @@ module Airbrake
9
9
  #
10
10
  # @since v8.0.0
11
11
  class ActionControllerNotifySubscriber
12
+ def initialize(rails_vsn)
13
+ @rails_7_or_above = rails_vsn.to_i >= 7
14
+ end
15
+
12
16
  def call(*args)
13
17
  return unless Airbrake::Config.instance.performance_stats
14
18
 
@@ -23,7 +27,16 @@ module Airbrake
23
27
  route: route,
24
28
  status_code: event.status_code,
25
29
  timing: event.duration,
26
- time: event.time,
30
+
31
+ # On Rails 7+ `ActiveSupport::Notifications::Event#time` returns an
32
+ # instance of Float. It represents monotonic time in milliseconds.
33
+ # Airbrake Ruby expects that the provided time is in seconds. Hence,
34
+ # we need to convert it from milliseconds to seconds. In the
35
+ # versions below Rails 7, time is an instance of Time.
36
+ #
37
+ # Relevant commit:
38
+ # https://github.com/rails/rails/commit/81d0dc90becfe0b8e7f7f26beb66c25d84b8ec7f
39
+ time: @rails_7_or_above ? event.time / 1000 : event.time,
27
40
  )
28
41
  end
29
42
  end
@@ -5,37 +5,10 @@ module Airbrake
5
5
  # This railtie works for any Rails application that supports railties (Rails
6
6
  # 3.2+ apps). It makes Airbrake Ruby work with Rails and report errors
7
7
  # occurring in the application automatically.
8
- #
9
- # rubocop:disable Metrics/BlockLength
10
8
  class Railtie < ::Rails::Railtie
11
9
  initializer('airbrake.middleware') do |app|
12
- # Since Rails 3.2 the ActionDispatch::DebugExceptions middleware is
13
- # responsible for logging exceptions and showing a debugging page in
14
- # case the request is local. We want to insert our middleware after
15
- # DebugExceptions, so we don't notify Airbrake about local requests.
16
-
17
- if ::Rails.version.to_i >= 5
18
- # Avoid the warning about deprecated strings.
19
- # Insert after DebugExceptions, since ConnectionManagement doesn't
20
- # exist in Rails 5 anymore.
21
- app.config.middleware.insert_after(
22
- ActionDispatch::DebugExceptions,
23
- Airbrake::Rack::Middleware,
24
- )
25
- elsif defined?(::ActiveRecord::ConnectionAdapters::ConnectionManagement)
26
- # Insert after ConnectionManagement to avoid DB connection leakage:
27
- # https://github.com/airbrake/airbrake/pull/568
28
- app.config.middleware.insert_after(
29
- ::ActiveRecord::ConnectionAdapters::ConnectionManagement,
30
- 'Airbrake::Rack::Middleware',
31
- )
32
- else
33
- # Insert after DebugExceptions for apps without ActiveRecord.
34
- app.config.middleware.insert_after(
35
- ActionDispatch::DebugExceptions,
36
- 'Airbrake::Rack::Middleware',
37
- )
38
- end
10
+ require 'airbrake/rails/railties/middleware_tie'
11
+ Railties::MiddlewareTie.new(app).call
39
12
  end
40
13
 
41
14
  rake_tasks do
@@ -47,82 +20,13 @@ module Airbrake
47
20
  end
48
21
 
49
22
  initializer('airbrake.action_controller') do
50
- ActiveSupport.on_load(:action_controller, run_once: true) do
51
- # Patches ActionController with methods that allow us to retrieve
52
- # interesting request data. Appends that information to notices.
53
- require 'airbrake/rails/action_controller'
54
- include Airbrake::Rails::ActionController
55
-
56
- # Cache route information for the duration of the request.
57
- require 'airbrake/rails/action_controller_route_subscriber'
58
- ActiveSupport::Notifications.subscribe(
59
- 'start_processing.action_controller',
60
- Airbrake::Rails::ActionControllerRouteSubscriber.new,
61
- )
62
-
63
- # Send route stats.
64
- require 'airbrake/rails/action_controller_notify_subscriber'
65
- ActiveSupport::Notifications.subscribe(
66
- 'process_action.action_controller',
67
- Airbrake::Rails::ActionControllerNotifySubscriber.new,
68
- )
69
-
70
- # Send performance breakdown: where a request spends its time.
71
- require 'airbrake/rails/action_controller_performance_breakdown_subscriber'
72
- ActiveSupport::Notifications.subscribe(
73
- 'process_action.action_controller',
74
- Airbrake::Rails::ActionControllerPerformanceBreakdownSubscriber.new,
75
- )
76
-
77
- require 'airbrake/rails/net_http' if defined?(Net) && defined?(Net::HTTP)
78
- require 'airbrake/rails/curb' if defined?(Curl) && defined?(Curl::CURB_VERSION)
79
- require 'airbrake/rails/http' if defined?(HTTP) && defined?(HTTP::Client)
80
- require 'airbrake/rails/http_client' if defined?(HTTPClient)
81
- require 'airbrake/rails/typhoeus' if defined?(Typhoeus)
82
-
83
- if defined?(Excon)
84
- require 'airbrake/rails/excon_subscriber'
85
- ActiveSupport::Notifications.subscribe(/excon/, Airbrake::Rails::Excon.new)
86
- ::Excon.defaults[:instrumentor] = ActiveSupport::Notifications
87
- end
88
- end
23
+ require 'airbrake/rails/railties/action_controller_tie'
24
+ Railties::ActionControllerTie.new.call
89
25
  end
90
26
 
91
27
  initializer('airbrake.active_record') do
92
- ActiveSupport.on_load(:active_record, run_once: true) do
93
- # Reports exceptions occurring in some bugged ActiveRecord callbacks.
94
- # Applicable only to the versions of Rails lower than 4.2.
95
- if defined?(::Rails) &&
96
- Gem::Version.new(::Rails.version) <= Gem::Version.new('4.2')
97
- require 'airbrake/rails/active_record'
98
- include Airbrake::Rails::ActiveRecord
99
- end
100
-
101
- if defined?(ActiveRecord)
102
- # Send SQL queries.
103
- require 'airbrake/rails/active_record_subscriber'
104
- ActiveSupport::Notifications.subscribe(
105
- 'sql.active_record', Airbrake::Rails::ActiveRecordSubscriber.new
106
- )
107
-
108
- # Filter out parameters from SQL body.
109
- if ::ActiveRecord::Base.respond_to?(:connection_db_config)
110
- # Rails 6.1+ deprecates "connection_config" in favor of
111
- # "connection_db_config", so we need an updated call.
112
- Airbrake.add_performance_filter(
113
- Airbrake::Filters::SqlFilter.new(
114
- ::ActiveRecord::Base.connection_db_config.configuration_hash[:adapter],
115
- ),
116
- )
117
- else
118
- Airbrake.add_performance_filter(
119
- Airbrake::Filters::SqlFilter.new(
120
- ::ActiveRecord::Base.connection_config[:adapter],
121
- ),
122
- )
123
- end
124
- end
125
- end
28
+ require 'airbrake/rails/railties/active_record_tie'
29
+ Railties::ActiveRecordTie.new.call
126
30
  end
127
31
 
128
32
  initializer('airbrake.active_job') do
@@ -146,6 +50,5 @@ module Airbrake
146
50
  end
147
51
  end
148
52
  end
149
- # rubocop:enable Metrics/BlockLength
150
53
  end
151
54
  end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'airbrake/rails/action_controller'
4
+ require 'airbrake/rails/action_controller_route_subscriber'
5
+ require 'airbrake/rails/action_controller_notify_subscriber'
6
+ require 'airbrake/rails/action_controller_performance_breakdown_subscriber'
7
+
8
+ module Airbrake
9
+ module Rails
10
+ module Railties
11
+ # Ties Airbrake APM (routes) and HTTP clients with Rails.
12
+ #
13
+ # @api private
14
+ # @since v13.0.1
15
+ class ActionControllerTie
16
+ def initialize
17
+ @route_subscriber = Airbrake::Rails::ActionControllerRouteSubscriber.new
18
+ @notify_subscriber = Airbrake::Rails::ActionControllerNotifySubscriber.new(
19
+ ::Rails.version,
20
+ )
21
+ @performance_breakdown_subscriber =
22
+ Airbrake::Rails::ActionControllerPerformanceBreakdownSubscriber.new
23
+ end
24
+
25
+ def call
26
+ ActiveSupport.on_load(:action_controller, run_once: true, yield: self) do
27
+ # Patches ActionController with methods that allow us to retrieve
28
+ # interesting request data. Appends that information to notices.
29
+ ::ActionController::Base.include(Airbrake::Rails::ActionController)
30
+
31
+ tie_routes_apm
32
+ tie_http_integrations
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def tie_routes_apm
39
+ [
40
+ # Cache route information for the duration of the request.
41
+ ['start_processing.action_controller', @route_subscriber],
42
+
43
+ # Send route stats.
44
+ ['process_action.action_controller', @notify_subscriber],
45
+
46
+ # Send performance breakdown: where a request spends its time.
47
+ ['process_action.action_controller', @performance_breakdown_subscriber],
48
+ ].each do |(event, callback)|
49
+ ActiveSupport::Notifications.subscribe(event, callback)
50
+ end
51
+ end
52
+
53
+ def tie_http_integrations
54
+ tie_net_http
55
+ tie_curl
56
+ tie_http
57
+ tie_http_client
58
+ tie_typhoeus
59
+ tie_excon
60
+ end
61
+
62
+ def tie_net_http
63
+ require 'airbrake/rails/net_http' if defined?(Net) && defined?(Net::HTTP)
64
+ end
65
+
66
+ def tie_curl
67
+ require 'airbrake/rails/curb' if defined?(Curl) && defined?(Curl::CURB_VERSION)
68
+ end
69
+
70
+ def tie_http
71
+ require 'airbrake/rails/http' if defined?(HTTP) && defined?(HTTP::Client)
72
+ end
73
+
74
+ def tie_http_client
75
+ require 'airbrake/rails/http_client' if defined?(HTTPClient)
76
+ end
77
+
78
+ def tie_typhoeus
79
+ require 'airbrake/rails/typhoeus' if defined?(Typhoeus)
80
+ end
81
+
82
+ def tie_excon
83
+ return unless defined?(Excon)
84
+
85
+ require 'airbrake/rails/excon_subscriber'
86
+ ActiveSupport::Notifications.subscribe(/excon/, Airbrake::Rails::Excon.new)
87
+ ::Excon.defaults[:instrumentor] = ActiveSupport::Notifications
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'airbrake/rails/active_record'
4
+ require 'airbrake/rails/active_record_subscriber'
5
+
6
+ module Airbrake
7
+ module Rails
8
+ module Railties
9
+ # Ties Airbrake APM (queries) with Rails.
10
+ #
11
+ # @api private
12
+ # @since v13.0.1
13
+ class ActiveRecordTie
14
+ def initialize
15
+ @active_record_subscriber = Airbrake::Rails::ActiveRecordSubscriber.new
16
+ end
17
+
18
+ def call
19
+ ActiveSupport.on_load(:active_record, run_once: true, yield: self) do
20
+ tie_activerecord_callback_fix
21
+ tie_activerecord_apm
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def tie_activerecord_callback_fix
28
+ # Reports exceptions occurring in some bugged ActiveRecord callbacks.
29
+ # Applicable only to the versions of Rails lower than 4.2.
30
+ return unless defined?(::Rails)
31
+ return if Gem::Version.new(::Rails.version) > Gem::Version.new('4.2')
32
+
33
+ ActiveRecord::Base.include(Airbrake::Rails::ActiveRecord)
34
+ end
35
+
36
+ def tie_activerecord_apm
37
+ # Some Rails apps don't use ActiveRecord.
38
+ return unless defined?(::ActiveRecord)
39
+
40
+ # However, some dependencies might still require it, so we need an
41
+ # extra check. Apps that don't need ActiveRecord will likely have no
42
+ # AR configurations defined. We will skip APM integration in that
43
+ # case. See: https://github.com/airbrake/airbrake/issues/1222
44
+ configurations = ::ActiveRecord::Base.configurations
45
+ return unless configurations.any?
46
+
47
+ # Send SQL queries.
48
+ ActiveSupport::Notifications.subscribe(
49
+ 'sql.active_record',
50
+ @active_record_subscriber,
51
+ )
52
+
53
+ # Filter out parameters from SQL body.
54
+ sql_filter = Airbrake::Filters::SqlFilter.new(
55
+ detect_activerecord_adapter(configurations),
56
+ )
57
+ Airbrake.add_performance_filter(sql_filter)
58
+ end
59
+
60
+ # Rails 6+ introduces the `configs_for` API instead of the deprecated
61
+ # `#[]`, so we need an updated call.
62
+ def detect_activerecord_adapter(configurations)
63
+ unless configurations.respond_to?(:configs_for)
64
+ return configurations[::Rails.env]['adapter']
65
+ end
66
+
67
+ cfg = configurations.configs_for(env_name: ::Rails.env).first
68
+ # Rails 7+ API : Rails 6 API.
69
+ cfg.respond_to?(:adapter) ? cfg.adapter : cfg.config['adapter']
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Airbrake
4
+ module Rails
5
+ module Railties
6
+ # Ties Airbrake Rails Middleware with Rails (error sending).
7
+ #
8
+ # Since Rails 3.2 the ActionDispatch::DebugExceptions middleware is
9
+ # responsible for logging exceptions and showing a debugging page in case
10
+ # the request is local. We want to insert our middleware after
11
+ # DebugExceptions, so we don't notify Airbrake about local requests.
12
+ #
13
+ # @api private
14
+ # @since v13.0.1
15
+ class MiddlewareTie
16
+ def initialize(app)
17
+ @app = app
18
+ @middleware = app.config.middleware
19
+ end
20
+
21
+ def call
22
+ return tie_rails_5_or_above if ::Rails.version.to_i >= 5
23
+
24
+ if defined?(::ActiveRecord::ConnectionAdapters::ConnectionManagement)
25
+ return tie_rails_4_or_below_with_active_record
26
+ end
27
+
28
+ tie_rails_4_or_below_with_active_record
29
+ end
30
+
31
+ private
32
+
33
+ # Avoid the warning about deprecated strings.
34
+ # Insert after DebugExceptions, since ConnectionManagement doesn't
35
+ # exist in Rails 5 anymore.
36
+ def tie_rails_5_or_above
37
+ @middleware.insert_after(
38
+ ActionDispatch::DebugExceptions,
39
+ Airbrake::Rack::Middleware,
40
+ )
41
+ end
42
+
43
+ # Insert after ConnectionManagement to avoid DB connection leakage:
44
+ # https://github.com/airbrake/airbrake/pull/568
45
+ def tie_rails_4_or_below_with_active_record
46
+ @middleware.insert_after(
47
+ ::ActiveRecord::ConnectionAdapters::ConnectionManagement,
48
+ 'Airbrake::Rack::Middleware',
49
+ )
50
+ end
51
+
52
+ # Insert after DebugExceptions for apps without ActiveRecord.
53
+ def tie_rails_4_or_below_without_active_record
54
+ @middleware.insert_after(
55
+ ActionDispatch::DebugExceptions,
56
+ 'Airbrake::Rack::Middleware',
57
+ )
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -53,11 +53,11 @@ namespace :airbrake do
53
53
  raise Airbrake::Error, 'airbrake-ruby is not configured' unless Airbrake.configured?
54
54
 
55
55
  deploy_params = {
56
- environment: ENV['ENVIRONMENT'],
57
- username: ENV['USERNAME'],
58
- revision: ENV['REVISION'],
59
- repository: ENV['REPOSITORY'],
60
- version: ENV['VERSION'],
56
+ environment: ENV.fetch('ENVIRONMENT', nil),
57
+ username: ENV.fetch('USERNAME', nil),
58
+ revision: ENV.fetch('REVISION', nil),
59
+ repository: ENV.fetch('REPOSITORY', nil),
60
+ version: ENV.fetch('VERSION', nil),
61
61
  }
62
62
  promise = Airbrake.notify_deploy(deploy_params)
63
63
  promise.then do
@@ -68,7 +68,7 @@ namespace :airbrake do
68
68
 
69
69
  desc 'Install a Heroku deploy hook to notify Airbrake of deploys'
70
70
  task :install_heroku_deploy_hook do
71
- app = ENV['HEROKU_APP']
71
+ app = ENV.fetch('HEROKU_APP', nil)
72
72
 
73
73
  config = Bundler.with_clean_env do
74
74
  `heroku config --shell#{" --app #{app}" if app}`
@@ -89,7 +89,7 @@ namespace :airbrake do
89
89
  " environment will be used."
90
90
  end
91
91
 
92
- unless (repo = ENV['REPOSITORY_URL'])
92
+ unless (repo = ENV.fetch('REPOSITORY_URL', nil))
93
93
  repo = `git remote get-url origin 2>/dev/null`.chomp
94
94
  if repo.empty?
95
95
  puts "Airbrake couldn't identify your app's repository."
@@ -3,5 +3,5 @@
3
3
  # We use Semantic Versioning v2.0.0
4
4
  # More information: http://semver.org/
5
5
  module Airbrake
6
- AIRBRAKE_VERSION = '13.0.0'
6
+ AIRBRAKE_VERSION = '13.0.1'
7
7
  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: 13.0.0
4
+ version: 13.0.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: 2022-01-18 00:00:00.000000000 Z
11
+ date: 2022-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: airbrake-ruby
@@ -335,6 +335,9 @@ files:
335
335
  - lib/airbrake/rails/http_client.rb
336
336
  - lib/airbrake/rails/net_http.rb
337
337
  - lib/airbrake/rails/railtie.rb
338
+ - lib/airbrake/rails/railties/action_controller_tie.rb
339
+ - lib/airbrake/rails/railties/active_record_tie.rb
340
+ - lib/airbrake/rails/railties/middleware_tie.rb
338
341
  - lib/airbrake/rails/typhoeus.rb
339
342
  - lib/airbrake/rake.rb
340
343
  - lib/airbrake/rake/tasks.rb