airbrake 11.0.3 → 13.0.3

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
  SHA256:
3
- metadata.gz: bd22c4ba5f388c063021267c805f9f72f9905c8e0f7a2b7e19d0f6a45c9718a9
4
- data.tar.gz: b919ee2bdae1a073c939b752d9827f3d8ecd6c30f18739019f9becbf6974a605
3
+ metadata.gz: 29da4f7ace6d408a64f855ddab6385fd40863235694a22cd31f5e46d1ae9c957
4
+ data.tar.gz: 4c08d2305072b5b48936e87dd2e53bf1610459637c7e23c7e75e118e475232b9
5
5
  SHA512:
6
- metadata.gz: 2362a03c41aebeddaf2e6bcd2272760ea0fb94b88a0dcabb644ab5c9b3a72ed72281f05f314f04491e27d99fae9c5353bbfaa4fc1d43f09d3e2316f6edfb02ba
7
- data.tar.gz: f260895a27e6f8e2368c2be1431344291d5dcdf731f0d4b71d4ab2f14de1265cb93759c888ad03592b02dabaa7944e9c4dfbfed4fb87b443e3aaddeba0321760
6
+ metadata.gz: 9ddb0e206f5723439061ca14af99f2c228f80f6db5907f07a16a8fde611b4f1e13533a0dea5e5b27d564a90e3044fb449fa09731274042c59fbb84bdb7f83af1
7
+ data.tar.gz: b78091a0e4391c27eea3c884130e1c6515cf10cf417ea29ec6c6df32075f5917dead2efd2f6e42395a64142f761d3870408ba5f7c7fb3ed1a90f53204c7bc8b2
@@ -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} \
@@ -7,41 +7,39 @@ module Delayed
7
7
  class Airbrake < ::Delayed::Plugin
8
8
  callbacks do |lifecycle|
9
9
  lifecycle.around(:invoke_job) do |job, *args, &block|
10
- begin
11
- timing = ::Airbrake::Benchmark.measure do
12
- # Forward the call to the next callback in the callback chain
13
- block.call(job, *args)
14
- end
15
- rescue Exception => exception # rubocop:disable Lint/RescueException
16
- params = job.as_json
10
+ timing = ::Airbrake::Benchmark.measure do
11
+ # Forward the call to the next callback in the callback chain
12
+ block.call(job, *args)
13
+ end
14
+ rescue Exception => exception # rubocop:disable Lint/RescueException
15
+ params = job.as_json
17
16
 
18
- # If DelayedJob is used through ActiveJob, it contains extra info.
19
- if job.payload_object.respond_to?(:job_data)
20
- params[:active_job] = job.payload_object.job_data
21
- job_class = job.payload_object.job_data['job_class']
22
- end
17
+ # If DelayedJob is used through ActiveJob, it contains extra info.
18
+ if job.payload_object.respond_to?(:job_data)
19
+ params[:active_job] = job.payload_object.job_data
20
+ job_class = job.payload_object.job_data['job_class']
21
+ end
23
22
 
24
- action = job_class || job.payload_object.class.name
23
+ action = job_class || job.payload_object.class.name
25
24
 
26
- ::Airbrake.notify(exception, params) do |notice|
27
- notice[:context][:component] = 'delayed_job'
28
- notice[:context][:action] = action
29
- end
25
+ ::Airbrake.notify(exception, params) do |notice|
26
+ notice[:context][:component] = 'delayed_job'
27
+ notice[:context][:action] = action
28
+ end
30
29
 
31
- ::Airbrake.notify_queue(
32
- queue: action,
33
- error_count: 1,
34
- timing: 0.01,
35
- )
30
+ ::Airbrake.notify_queue(
31
+ queue: action,
32
+ error_count: 1,
33
+ timing: 0.01,
34
+ )
36
35
 
37
- raise exception
38
- else
39
- ::Airbrake.notify_queue(
40
- queue: job_class || job.payload_object.class.name,
41
- error_count: 0,
42
- timing: timing,
43
- )
44
- end
36
+ raise exception
37
+ else
38
+ ::Airbrake.notify_queue(
39
+ queue: job_class || job.payload_object.class.name,
40
+ error_count: 0,
41
+ timing: timing,
42
+ )
45
43
  end
46
44
  end
47
45
  end
@@ -9,7 +9,7 @@ module Airbrake
9
9
  #
10
10
  # @example
11
11
  # # Create a logger like you normally do and decorate it.
12
- # logger = Airbrake::AirbrakeLogger.new(Logger.new(STDOUT))
12
+ # logger = Airbrake::AirbrakeLogger.new(Logger.new($stdout))
13
13
  #
14
14
  # # Just use the logger like you normally do.
15
15
  # logger.fatal('oops')
@@ -24,6 +24,8 @@ module Airbrake
24
24
  attr_reader :airbrake_level
25
25
 
26
26
  def initialize(logger)
27
+ super
28
+
27
29
  __setobj__(logger)
28
30
  @airbrake_notifier = Airbrake
29
31
  self.level = logger.level
@@ -20,14 +20,9 @@ module Airbrake
20
20
  context = notice[:context]
21
21
 
22
22
  context[:url] = request.url
23
- context[:userAddr] =
24
- if request.respond_to?(:remote_ip)
25
- request.remote_ip
26
- else
27
- request.ip
28
- end
29
23
  context[:userAgent] = request.user_agent
30
24
 
25
+ add_ip(context, request)
31
26
  add_framework_version(context)
32
27
 
33
28
  controller = request.env['action_controller.instance']
@@ -60,6 +55,15 @@ module Airbrake
60
55
  }
61
56
  end
62
57
  end
58
+
59
+ def add_ip(context, request)
60
+ context[:userAddr] =
61
+ if request.respond_to?(:remote_ip)
62
+ request.remote_ip
63
+ else
64
+ request.ip
65
+ end
66
+ end
63
67
  end
64
68
  end
65
69
  end
@@ -57,6 +57,7 @@ module Airbrake
57
57
  klass.module_exec do
58
58
  mod = __airbrake_capture_timing_module__
59
59
  mod.module_exec do
60
+ # rubocop:disable Style/DocumentDynamicEvalDefinition
60
61
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
61
62
  def #{method_name}(#{args})
62
63
  Airbrake::Rack.capture_timing(#{label.to_s.inspect}) do
@@ -65,6 +66,7 @@ module Airbrake
65
66
  end
66
67
  #{visibility} :#{method_name}
67
68
  RUBY
69
+ # rubocop:enable Style/DocumentDynamicEvalDefinition
68
70
  end
69
71
  prepend mod
70
72
  end
@@ -83,6 +85,7 @@ module Airbrake
83
85
  klass.module_exec do
84
86
  alias_method wrapped_method_name, method_name
85
87
  remove_method method_name if needs_removal
88
+ # rubocop:disable Style/DocumentDynamicEvalDefinition
86
89
  module_eval <<-RUBY, __FILE__, __LINE__ + 1
87
90
  def #{method_name}(#{args})
88
91
  Airbrake::Rack.capture_timing(#{label.to_s.inspect}) do
@@ -91,6 +94,7 @@ module Airbrake
91
94
  end
92
95
  #{visibility} :#{method_name}
93
96
  RUBY
97
+ # rubocop:enable Style/DocumentDynamicEvalDefinition
94
98
  end
95
99
  end
96
100
 
@@ -35,7 +35,7 @@ module Airbrake
35
35
  def sinatra_route(request)
36
36
  return unless (route = request.env['sinatra.route'])
37
37
 
38
- route.split(' ').drop(1).join(' ')
38
+ route.split.drop(1).join(' ')
39
39
  end
40
40
 
41
41
  def action_dispatch_request?(request)
@@ -40,12 +40,12 @@ module Airbrake
40
40
  # Skip "catch-all" routes such as:
41
41
  # get '*path => 'pages#about'
42
42
  #
43
- # @todo The `glob?` method was added in Rails v4.2.0.beta1. We
44
- # should remove the `respond_to?` check once we drop old Rails
45
- # versions support.
43
+ # Ideally, we should be using `route.glob?` but in Rails 7+ this
44
+ # call would fail with a `NoMethodError`. This is because in
45
+ # Rails 7+ the AST for the route is not kept in memory anymore.
46
46
  #
47
- # https://github.com/rails/rails/commit/5460591f0226a9d248b7b4f89186bd5553e7768f
48
- next if route.respond_to?(:glob?) && route.glob?
47
+ # See: https://github.com/rails/rails/pull/43006#discussion_r783895766
48
+ next if route.path.spec.any?(ActionDispatch::Journey::Nodes::Star)
49
49
 
50
50
  path =
51
51
  if engine == ::Rails.application
@@ -10,10 +10,14 @@ module Airbrake
10
10
  # @see https://github.com/rails/rails/issues/8987
11
11
  HTML_RESPONSE_WILDCARD = "*/*"
12
12
 
13
+ # @return [Integer]
14
+ MILLISECOND = 1000
15
+
13
16
  include Airbrake::Loggable
14
17
 
15
18
  def initialize(*args)
16
19
  @event = ActiveSupport::Notifications::Event.new(*args)
20
+ @rails_7_or_greater = ::Rails::VERSION::MAJOR >= 7
17
21
  end
18
22
 
19
23
  def method
@@ -42,7 +46,15 @@ module Airbrake
42
46
  end
43
47
 
44
48
  def time
45
- @event.time
49
+ # On Rails 7+ `ActiveSupport::Notifications::Event#time` returns an
50
+ # instance of Float. It represents monotonic time in milliseconds.
51
+ # Airbrake Ruby expects that the provided time is in seconds. Hence,
52
+ # we need to convert it from milliseconds to seconds. In the
53
+ # versions below Rails 7, time is an instance of Time.
54
+ #
55
+ # Relevant commit:
56
+ # https://github.com/rails/rails/commit/81d0dc90becfe0b8e7f7f26beb66c25d84b8ec7f
57
+ @rails_7_or_greater ? @event.time / MILLISECOND : @event.time
46
58
  end
47
59
 
48
60
  def groups
@@ -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,90 @@
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
+ @performance_breakdown_subscriber =
20
+ Airbrake::Rails::ActionControllerPerformanceBreakdownSubscriber.new
21
+ end
22
+
23
+ def call
24
+ ActiveSupport.on_load(:action_controller, run_once: true, yield: self) do
25
+ # Patches ActionController with methods that allow us to retrieve
26
+ # interesting request data. Appends that information to notices.
27
+ ::ActionController::Base.include(Airbrake::Rails::ActionController)
28
+
29
+ tie_routes_apm
30
+ tie_http_integrations
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def tie_routes_apm
37
+ [
38
+ # Cache route information for the duration of the request.
39
+ ['start_processing.action_controller', @route_subscriber],
40
+
41
+ # Send route stats.
42
+ ['process_action.action_controller', @notify_subscriber],
43
+
44
+ # Send performance breakdown: where a request spends its time.
45
+ ['process_action.action_controller', @performance_breakdown_subscriber],
46
+ ].each do |(event, callback)|
47
+ ActiveSupport::Notifications.subscribe(event, callback)
48
+ end
49
+ end
50
+
51
+ def tie_http_integrations
52
+ tie_net_http
53
+ tie_curl
54
+ tie_http
55
+ tie_http_client
56
+ tie_typhoeus
57
+ tie_excon
58
+ end
59
+
60
+ def tie_net_http
61
+ require 'airbrake/rails/net_http' if defined?(Net) && defined?(Net::HTTP)
62
+ end
63
+
64
+ def tie_curl
65
+ require 'airbrake/rails/curb' if defined?(Curl) && defined?(Curl::CURB_VERSION)
66
+ end
67
+
68
+ def tie_http
69
+ require 'airbrake/rails/http' if defined?(HTTP) && defined?(HTTP::Client)
70
+ end
71
+
72
+ def tie_http_client
73
+ require 'airbrake/rails/http_client' if defined?(HTTPClient)
74
+ end
75
+
76
+ def tie_typhoeus
77
+ require 'airbrake/rails/typhoeus' if defined?(Typhoeus)
78
+ end
79
+
80
+ def tie_excon
81
+ return unless defined?(Excon)
82
+
83
+ require 'airbrake/rails/excon_subscriber'
84
+ ActiveSupport::Notifications.subscribe(/excon/, Airbrake::Rails::Excon.new)
85
+ ::Excon.defaults[:instrumentor] = ActiveSupport::Notifications
86
+ end
87
+ end
88
+ end
89
+ end
90
+ 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_without_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
@@ -11,7 +11,7 @@ module Airbrake
11
11
  level = (::Rails.logger ? ::Rails.logger.level : Logger::ERROR)
12
12
 
13
13
  if ENV['RAILS_LOG_TO_STDOUT'].present?
14
- Logger.new(STDOUT, level: level)
14
+ Logger.new($stdout, level: level)
15
15
  else
16
16
  Logger.new(::Rails.root.join('log', 'airbrake.log'), level: level)
17
17
  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}`
@@ -85,11 +85,11 @@ namespace :airbrake do
85
85
 
86
86
  unless (env = heroku_env['RAILS_ENV'])
87
87
  env = 'production'
88
- puts "Airbrake couldn't identify your app's environment, so the '#{env}'" \
89
- " environment will be used."
88
+ puts "Airbrake couldn't identify your app's environment, " \
89
+ "so the '#{env}' 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."
@@ -5,10 +5,8 @@ module Airbrake
5
5
  # Provides integration with Shoryuken.
6
6
  class ErrorHandler
7
7
  # rubocop:disable Lint/RescueException
8
- def call(worker, queue, _sqs_msg, body)
9
- timing = Airbrake::Benchmark.measure do
10
- yield
11
- end
8
+ def call(worker, queue, _sqs_msg, body, &block)
9
+ timing = Airbrake::Benchmark.measure(&block)
12
10
  rescue Exception => exception
13
11
  notify_airbrake(exception, worker, queue, body)
14
12
  Airbrake.notify_queue(
@@ -6,10 +6,8 @@ module Airbrake
6
6
  module Sidekiq
7
7
  # Provides integration with Sidekiq v2+.
8
8
  class ErrorHandler
9
- def call(_worker, context, _queue)
10
- timing = Airbrake::Benchmark.measure do
11
- yield
12
- end
9
+ def call(_worker, context, _queue, &block)
10
+ timing = Airbrake::Benchmark.measure(&block)
13
11
  rescue Exception => exception # rubocop:disable Lint/RescueException
14
12
  notify_airbrake(exception, context)
15
13
  Airbrake.notify_queue(
@@ -38,7 +36,7 @@ module Airbrake
38
36
  # @return [String] job's name. When ActiveJob is present, retrieve
39
37
  # job_class. When used directly, use worker's name
40
38
  def action(context)
41
- klass = context['class'] || context[:job] && context[:job]['class']
39
+ klass = context['class'] || (context[:job] && context[:job]['class'])
42
40
  return klass unless context[:job] && context[:job]['args'].first.is_a?(Hash)
43
41
  return klass unless (job_class = context[:job]['args'].first['job_class'])
44
42
 
@@ -48,24 +48,22 @@ module Airbrake
48
48
  define_method(
49
49
  ::Sneakers::Worker.method_defined?(:process_work) ? :process_work : :do_work,
50
50
  ) do |delivery_info, metadata, msg, handler|
51
- begin
52
- timing = Airbrake::Benchmark.measure do
53
- super(delivery_info, metadata, msg, handler)
54
- end
55
- rescue Exception => exception # rubocop:disable Lint/RescueException
56
- Airbrake.notify_queue(
57
- queue: self.class.to_s,
58
- error_count: 1,
59
- timing: 0.01,
60
- )
61
- raise exception
62
- else
63
- Airbrake.notify_queue(
64
- queue: self.class.to_s,
65
- error_count: 0,
66
- timing: timing,
67
- )
51
+ timing = Airbrake::Benchmark.measure do
52
+ super(delivery_info, metadata, msg, handler)
68
53
  end
54
+ rescue Exception => exception # rubocop:disable Lint/RescueException
55
+ Airbrake.notify_queue(
56
+ queue: self.class.to_s,
57
+ error_count: 1,
58
+ timing: 0.01,
59
+ )
60
+ raise exception
61
+ else
62
+ Airbrake.notify_queue(
63
+ queue: self.class.to_s,
64
+ error_count: 0,
65
+ timing: timing,
66
+ )
69
67
  end
70
68
  end
71
69
  end
@@ -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 = '11.0.3'
6
+ AIRBRAKE_VERSION = '13.0.3'
7
7
  end
@@ -3,22 +3,19 @@
3
3
  # Creates the Airbrake initializer file for Rails apps.
4
4
  #
5
5
  # @example Invokation from terminal
6
- # rails generate airbrake PROJECT_KEY PROJECT_ID [NAME]
6
+ # rails generate airbrake [NAME]
7
7
  #
8
8
  class AirbrakeGenerator < Rails::Generators::Base
9
9
  # Adds current directory to source paths, so we can find the template file.
10
10
  source_root File.expand_path(__dir__)
11
11
 
12
- argument :project_id, required: false
13
- argument :project_key, required: false
14
-
15
12
  # Makes the NAME option optional, which allows to subclass from Base, so we
16
13
  # can pass arguments to the ERB template.
17
14
  #
18
- # @see http://asciicasts.com/episodes/218-making-generators-in-rails-3
15
+ # @see https://asciicasts.com/episodes/218-making-generators-in-rails-3.html
19
16
  argument :name, type: :string, default: 'application'
20
17
 
21
- desc 'Configures the Airbrake notifier with your project id and project key'
18
+ desc 'Configures the Airbrake notifier'
22
19
  def generate_layout
23
20
  template 'airbrake_initializer.rb.erb', 'config/initializers/airbrake.rb'
24
21
  end
@@ -1,80 +1,80 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Airbrake is an online tool that provides robust exception tracking in your Rails
4
- # applications. In doing so, it allows you to easily review errors, tie an error
5
- # to an individual piece of code, and trace the cause back to recent
6
- # changes. Airbrake enables for easy categorization, searching, and prioritization
7
- # of exceptions so that when errors occur, your team can quickly determine the
8
- # root cause.
3
+ # Airbrake is an online tool that provides robust exception tracking in your
4
+ # Rails applications. In doing so, it allows you to easily review errors, tie an
5
+ # error to an individual piece of code, and trace the cause back to recent
6
+ # changes. Airbrake enables for easy categorization, searching, and
7
+ # prioritization of exceptions so that when errors occur, your team can quickly
8
+ # determine the root cause.
9
9
  #
10
10
  # Configuration details:
11
11
  # https://github.com/airbrake/airbrake-ruby#configuration
12
- Airbrake.configure do |c|
13
- # You must set both project_id & project_key. To find your project_id and
14
- # project_key navigate to your project's General Settings and copy the values
15
- # from the right sidebar.
16
- # https://github.com/airbrake/airbrake-ruby#project_id--project_key
17
- <% if project_id -%>
18
- c.project_id = <%= project_id %>
19
- <% else -%>
20
- c.project_id = ENV['AIRBRAKE_PROJECT_ID']
21
- <% end -%>
22
- <% if project_key -%>
23
- c.project_key = '<%= project_key %>'
24
- <% else -%>
25
- c.project_key = ENV['AIRBRAKE_API_KEY']
26
- <% end -%>
12
+ if (project_id = ENV['AIRBRAKE_PROJECT_ID']) &&
13
+ project_key = (ENV['AIRBRAKE_PROJECT_KEY'] || ENV['AIRBRAKE_API_KEY'])
14
+ Airbrake.configure do |c|
15
+ # You must set both project_id & project_key. To find your project_id and
16
+ # project_key navigate to your project's General Settings and copy the
17
+ # values from the right sidebar.
18
+ # https://github.com/airbrake/airbrake-ruby#project_id--project_key
19
+ c.project_id = project_id
20
+ c.project_key = project_key
27
21
 
28
- # Configures the root directory of your project. Expects a String or a
29
- # Pathname, which represents the path to your project. Providing this option
30
- # helps us to filter out repetitive data from backtrace frames and link to
31
- # GitHub files from our dashboard.
32
- # https://github.com/airbrake/airbrake-ruby#root_directory
33
- c.root_directory = Rails.root
22
+ # Configures the root directory of your project. Expects a String or a
23
+ # Pathname, which represents the path to your project. Providing this option
24
+ # helps us to filter out repetitive data from backtrace frames and link to
25
+ # GitHub files from our dashboard.
26
+ # https://github.com/airbrake/airbrake-ruby#root_directory
27
+ c.root_directory = Rails.root
34
28
 
35
- # By default, Airbrake Ruby outputs to STDOUT. In Rails apps it makes sense to
36
- # use the Rails' logger.
37
- # https://github.com/airbrake/airbrake-ruby#logger
38
- c.logger = Airbrake::Rails.logger
29
+ # By default, Airbrake Ruby outputs to STDOUT. In Rails apps it makes sense
30
+ # to use the Rails' logger.
31
+ # https://github.com/airbrake/airbrake-ruby#logger
32
+ c.logger = Airbrake::Rails.logger
39
33
 
40
- # Configures the environment the application is running in. Helps the Airbrake
41
- # dashboard to distinguish between exceptions occurring in different
42
- # environments.
43
- # NOTE: This option must be set in order to make the 'ignore_environments'
44
- # option work.
45
- # https://github.com/airbrake/airbrake-ruby#environment
46
- c.environment = Rails.env
34
+ # Configures the environment the application is running in. Helps the
35
+ # Airbrake dashboard to distinguish between exceptions occurring in
36
+ # different environments.
37
+ # NOTE: This option must be set in order to make the 'ignore_environments'
38
+ # option work.
39
+ # https://github.com/airbrake/airbrake-ruby#environment
40
+ c.environment = Rails.env
47
41
 
48
- # Setting this option allows Airbrake to filter exceptions occurring in
49
- # unwanted environments such as :test.
50
- # NOTE: This option *does not* work if you don't set the 'environment' option.
51
- # https://github.com/airbrake/airbrake-ruby#ignore_environments
52
- c.ignore_environments = %w[test]
42
+ # Setting this option allows Airbrake to filter exceptions occurring in
43
+ # unwanted environments such as :test. NOTE: This option *does not* work if
44
+ # you don't set the 'environment' option.
45
+ # https://github.com/airbrake/airbrake-ruby#ignore_environments
46
+ c.ignore_environments = %w[test]
53
47
 
54
- # A list of parameters that should be filtered out of what is sent to
55
- # Airbrake. By default, all "password" attributes will have their contents
56
- # replaced.
57
- # https://github.com/airbrake/airbrake-ruby#blocklist_keys
58
- c.blocklist_keys = [/password/i, /authorization/i]
48
+ # A list of parameters that should be filtered out of what is sent to
49
+ # Airbrake. By default, all "password" attributes will have their contents
50
+ # replaced.
51
+ # https://github.com/airbrake/airbrake-ruby#blocklist_keys
52
+ c.blocklist_keys = [/password/i, /authorization/i]
59
53
 
60
- # Alternatively, you can integrate with Rails' filter_parameters.
61
- # Read more: https://goo.gl/gqQ1xS
62
- # c.blocklist_keys = Rails.application.config.filter_parameters
63
- end
54
+ # Alternatively, you can integrate with Rails' filter_parameters.
55
+ # Read more: https://goo.gl/gqQ1xS
56
+ # c.blocklist_keys = Rails.application.config.filter_parameters
57
+ end
64
58
 
65
- # A filter that collects request body information. Enable it if you are sure you
66
- # don't send sensitive information to Airbrake in your body (such as passwords).
67
- # https://github.com/airbrake/airbrake#requestbodyfilter
68
- # Airbrake.add_filter(Airbrake::Rack::RequestBodyFilter.new)
59
+ # A filter that collects request body information. Enable it if you are sure you
60
+ # don't send sensitive information to Airbrake in your body (such as passwords).
61
+ # https://github.com/airbrake/airbrake#requestbodyfilter
62
+ # Airbrake.add_filter(Airbrake::Rack::RequestBodyFilter.new)
69
63
 
70
- # Attaches thread & fiber local variables along with general thread information.
71
- # Airbrake.add_filter(Airbrake::Filters::ThreadFilter.new)
64
+ # Attaches thread & fiber local variables along with general thread information.
65
+ # Airbrake.add_filter(Airbrake::Filters::ThreadFilter.new)
72
66
 
73
- # Attaches loaded dependencies to the notice object
74
- # (under context/versions/dependencies).
75
- # Airbrake.add_filter(Airbrake::Filters::DependencyFilter.new)
67
+ # Attaches loaded dependencies to the notice object
68
+ # (under context/versions/dependencies).
69
+ # Airbrake.add_filter(Airbrake::Filters::DependencyFilter.new)
76
70
 
77
- # If you want to convert your log messages to Airbrake errors, we offer an
78
- # integration with the Logger class from stdlib.
79
- # https://github.com/airbrake/airbrake#logger
80
- # Rails.logger = Airbrake::AirbrakeLogger.new(Rails.logger)
71
+ # If you want to convert your log messages to Airbrake errors, we offer an
72
+ # integration with the Logger class from stdlib.
73
+ # https://github.com/airbrake/airbrake#logger
74
+ # Rails.logger = Airbrake::AirbrakeLogger.new(Rails.logger)
75
+ else
76
+ Rails.logger.warn(
77
+ "#{__FILE__}: Airbrake project id or project key is not set. " \
78
+ "Skipping Airbrake configuration"
79
+ )
80
+ 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: 11.0.3
4
+ version: 13.0.3
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: 2021-05-13 00:00:00.000000000 Z
11
+ date: 2022-09-20 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: '5.1'
19
+ version: '6.0'
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: '5.1'
26
+ version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -137,75 +137,61 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: sneakers
140
+ name: rack-test
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '2'
145
+ version: '2.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '2'
153
- - !ruby/object:Gem::Dependency
154
- name: rack-test
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - '='
158
- - !ruby/object:Gem::Version
159
- version: 0.6.3
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - '='
165
- - !ruby/object:Gem::Version
166
- version: 0.6.3
152
+ version: '2.0'
167
153
  - !ruby/object:Gem::Dependency
168
154
  name: redis
169
155
  requirement: !ruby/object:Gem::Requirement
170
156
  requirements:
171
- - - '='
157
+ - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: 4.1.4
159
+ version: '4.5'
174
160
  type: :development
175
161
  prerelease: false
176
162
  version_requirements: !ruby/object:Gem::Requirement
177
163
  requirements:
178
- - - '='
164
+ - - "~>"
179
165
  - !ruby/object:Gem::Version
180
- version: 4.1.4
166
+ version: '4.5'
181
167
  - !ruby/object:Gem::Dependency
182
168
  name: sidekiq
183
169
  requirement: !ruby/object:Gem::Requirement
184
170
  requirements:
185
171
  - - "~>"
186
172
  - !ruby/object:Gem::Version
187
- version: '5'
173
+ version: '6'
188
174
  type: :development
189
175
  prerelease: false
190
176
  version_requirements: !ruby/object:Gem::Requirement
191
177
  requirements:
192
178
  - - "~>"
193
179
  - !ruby/object:Gem::Version
194
- version: '5'
180
+ version: '6'
195
181
  - !ruby/object:Gem::Dependency
196
182
  name: curb
197
183
  requirement: !ruby/object:Gem::Requirement
198
184
  requirements:
199
185
  - - "~>"
200
186
  - !ruby/object:Gem::Version
201
- version: '0.9'
187
+ version: '1.0'
202
188
  type: :development
203
189
  prerelease: false
204
190
  version_requirements: !ruby/object:Gem::Requirement
205
191
  requirements:
206
192
  - - "~>"
207
193
  - !ruby/object:Gem::Version
208
- version: '0.9'
194
+ version: '1.0'
209
195
  - !ruby/object:Gem::Dependency
210
196
  name: excon
211
197
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +212,14 @@ dependencies:
226
212
  requirements:
227
213
  - - "~>"
228
214
  - !ruby/object:Gem::Version
229
- version: '2.2'
215
+ version: '5.0'
230
216
  type: :development
231
217
  prerelease: false
232
218
  version_requirements: !ruby/object:Gem::Requirement
233
219
  requirements:
234
220
  - - "~>"
235
221
  - !ruby/object:Gem::Version
236
- version: '2.2'
222
+ version: '5.0'
237
223
  - !ruby/object:Gem::Dependency
238
224
  name: httpclient
239
225
  requirement: !ruby/object:Gem::Requirement
@@ -263,53 +249,19 @@ dependencies:
263
249
  - !ruby/object:Gem::Version
264
250
  version: '1.3'
265
251
  - !ruby/object:Gem::Dependency
266
- name: ethon
267
- requirement: !ruby/object:Gem::Requirement
268
- requirements:
269
- - - '='
270
- - !ruby/object:Gem::Version
271
- version: 0.12.0
272
- type: :development
273
- prerelease: false
274
- version_requirements: !ruby/object:Gem::Requirement
275
- requirements:
276
- - - '='
277
- - !ruby/object:Gem::Version
278
- version: 0.12.0
279
- - !ruby/object:Gem::Dependency
280
- name: public_suffix
252
+ name: redis-namespace
281
253
  requirement: !ruby/object:Gem::Requirement
282
254
  requirements:
283
255
  - - "~>"
284
256
  - !ruby/object:Gem::Version
285
- version: '4.0'
286
- - - "<"
287
- - !ruby/object:Gem::Version
288
- version: '5.0'
257
+ version: '1.8'
289
258
  type: :development
290
259
  prerelease: false
291
260
  version_requirements: !ruby/object:Gem::Requirement
292
261
  requirements:
293
262
  - - "~>"
294
263
  - !ruby/object:Gem::Version
295
- version: '4.0'
296
- - - "<"
297
- - !ruby/object:Gem::Version
298
- version: '5.0'
299
- - !ruby/object:Gem::Dependency
300
- name: redis-namespace
301
- requirement: !ruby/object:Gem::Requirement
302
- requirements:
303
- - - '='
304
- - !ruby/object:Gem::Version
305
- version: 1.6.0
306
- type: :development
307
- prerelease: false
308
- version_requirements: !ruby/object:Gem::Requirement
309
- requirements:
310
- - - '='
311
- - !ruby/object:Gem::Version
312
- version: 1.6.0
264
+ version: '1.8'
313
265
  description: |
314
266
  Airbrake is an online tool that provides robust exception tracking in any of
315
267
  your Ruby applications. In doing so, it allows you to easily review errors, tie
@@ -363,6 +315,9 @@ files:
363
315
  - lib/airbrake/rails/http_client.rb
364
316
  - lib/airbrake/rails/net_http.rb
365
317
  - lib/airbrake/rails/railtie.rb
318
+ - lib/airbrake/rails/railties/action_controller_tie.rb
319
+ - lib/airbrake/rails/railties/active_record_tie.rb
320
+ - lib/airbrake/rails/railties/middleware_tie.rb
366
321
  - lib/airbrake/rails/typhoeus.rb
367
322
  - lib/airbrake/rake.rb
368
323
  - lib/airbrake/rake/tasks.rb
@@ -377,7 +332,8 @@ files:
377
332
  homepage: https://airbrake.io
378
333
  licenses:
379
334
  - MIT
380
- metadata: {}
335
+ metadata:
336
+ rubygems_mfa_required: 'true'
381
337
  post_install_message:
382
338
  rdoc_options: []
383
339
  require_paths:
@@ -386,14 +342,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
386
342
  requirements:
387
343
  - - ">="
388
344
  - !ruby/object:Gem::Version
389
- version: '2.3'
345
+ version: '2.6'
390
346
  required_rubygems_version: !ruby/object:Gem::Requirement
391
347
  requirements:
392
348
  - - ">="
393
349
  - !ruby/object:Gem::Version
394
350
  version: '0'
395
351
  requirements: []
396
- rubygems_version: 3.1.2
352
+ rubygems_version: 3.3.3
397
353
  signing_key:
398
354
  specification_version: 4
399
355
  summary: Airbrake is an online tool that provides robust exception tracking in any