airbrake 6.0.0 → 6.1.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/airbrake.rb +8 -14
  3. data/lib/airbrake/delayed_job.rb +49 -0
  4. data/lib/airbrake/delayed_job/plugin.rb +4 -50
  5. data/lib/airbrake/logger.rb +102 -0
  6. data/lib/airbrake/logger/airbrake_logger.rb +4 -105
  7. data/lib/airbrake/rack.rb +7 -0
  8. data/lib/airbrake/rack/context_filter.rb +5 -0
  9. data/lib/airbrake/rack/http_headers_filter.rb +9 -1
  10. data/lib/airbrake/rack/http_params_filter.rb +9 -1
  11. data/lib/airbrake/rack/request_body_filter.rb +5 -0
  12. data/lib/airbrake/rack/session_filter.rb +8 -0
  13. data/lib/airbrake/rails.rb +79 -0
  14. data/lib/airbrake/rails/active_record.rb +1 -1
  15. data/lib/airbrake/rails/railtie.rb +4 -78
  16. data/lib/airbrake/rake.rb +64 -0
  17. data/lib/airbrake/rake/task_ext.rb +4 -65
  18. data/lib/airbrake/rake/tasks.rb +12 -1
  19. data/lib/airbrake/resque.rb +17 -0
  20. data/lib/airbrake/resque/failure.rb +4 -17
  21. data/lib/airbrake/shoryuken.rb +41 -0
  22. data/lib/airbrake/shoryuken/error_handler.rb +4 -43
  23. data/lib/airbrake/sidekiq.rb +37 -0
  24. data/lib/airbrake/sidekiq/error_handler.rb +4 -37
  25. data/lib/airbrake/version.rb +1 -1
  26. data/spec/apps/rack/dummy_app.rb +1 -1
  27. data/spec/apps/rails/dummy_app.rb +30 -1
  28. data/spec/apps/rails/logs/40.log +4 -895
  29. data/spec/apps/rails/logs/42.log +19 -5438
  30. data/spec/apps/rails/logs/50.log +6611 -10
  31. data/spec/apps/rails/logs/51.log +743 -0
  32. data/spec/apps/rails/logs/52.log +249 -0
  33. data/spec/integration/rails/rails_spec.rb +16 -12
  34. data/spec/integration/shared_examples/rack_examples.rb +14 -20
  35. data/spec/spec_helper.rb +3 -3
  36. data/spec/unit/{logger/airbrake_logger_spec.rb → logger_spec.rb} +0 -0
  37. data/spec/unit/rack/context_filter_spec.rb +2 -2
  38. data/spec/unit/rack/http_headers_filter_spec.rb +7 -7
  39. data/spec/unit/rack/http_params_filter_spec.rb +8 -2
  40. data/spec/unit/rake/tasks_spec.rb +5 -5
  41. data/spec/unit/{shoryuken/error_handler_spec.rb → shoryuken_spec.rb} +12 -7
  42. data/spec/unit/{sidekiq/error_handler_spec.rb → sidekiq_spec.rb} +12 -8
  43. metadata +32 -18
  44. data/spec/apps/rails/logs/32.log +0 -852
  45. data/spec/apps/rails/logs/41.log +0 -453
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fd6dc0541e7ed8b5c12e51970d26ef14ad61d75
4
- data.tar.gz: 5dbd13f274588c4bfe444914c0dfdd28985e8693
3
+ metadata.gz: b23632aa16626fa2b627b3958b9b5f9908327aaa
4
+ data.tar.gz: e85e64b1ee1fc6c9df543edf509e93fd2601ba51
5
5
  SHA512:
6
- metadata.gz: 2463751a7a8e16c003acc7671e0a88db25878462fe6cf4fc74ff07160636c87579a1c05eddbe6f16e25fe570d61832c3ca86fc92961ea4c813e9e5d2ef1077e4
7
- data.tar.gz: 2884c1a743235a0e7c25dc1f07a8f662a6d486d0de7e8fe729b2cfe4a3e33007566b2e258b40994d4495aa849e375fcbbe103637b41c78d8ac8e2729b4069a50
6
+ metadata.gz: 7abde81c419140fdbb0266b8a2df9f40d04cac64e67edf9b3d820033c2b0afb7de7f4ded0636920806821dfc9b765a33bb8299fdd0fccec54b719c0759417922
7
+ data.tar.gz: 67938ba3d514eb4b7c259581eb35139ba1857ff3491adebbc6a6c788db6673a5087cb29dbf95571fd010cc9974c401ab631040f181cb842ad10a326e49b84559
@@ -9,24 +9,18 @@ require 'airbrake/version'
9
9
 
10
10
  # Automatically load needed files for the environment the library is running in.
11
11
  if defined?(Rack)
12
- require 'airbrake/rack/user'
13
- require 'airbrake/rack/context_filter'
14
- require 'airbrake/rack/session_filter'
15
- require 'airbrake/rack/http_params_filter'
16
- require 'airbrake/rack/http_headers_filter'
17
- require 'airbrake/rack/request_body_filter'
18
- require 'airbrake/rack/middleware'
12
+ require 'airbrake/rack'
19
13
 
20
- require 'airbrake/rails/railtie' if defined?(Rails)
14
+ require 'airbrake/rails' if defined?(Rails)
21
15
  end
22
16
 
23
- require 'airbrake/rake/task_ext' if defined?(Rake::Task)
24
- require 'airbrake/resque/failure' if defined?(Resque)
25
- require 'airbrake/sidekiq/error_handler' if defined?(Sidekiq)
26
- require 'airbrake/shoryuken/error_handler' if defined?(Shoryuken)
27
- require 'airbrake/delayed_job/plugin' if defined?(Delayed)
17
+ require 'airbrake/rake' if defined?(Rake::Task)
18
+ require 'airbrake/resque' if defined?(Resque)
19
+ require 'airbrake/sidekiq' if defined?(Sidekiq)
20
+ require 'airbrake/shoryuken' if defined?(Shoryuken)
21
+ require 'airbrake/delayed_job' if defined?(Delayed)
28
22
 
29
- require 'airbrake/logger/airbrake_logger'
23
+ require 'airbrake/logger'
30
24
 
31
25
  # Notify of unhandled exceptions, if there were any, but ignore SystemExit.
32
26
  at_exit do
@@ -0,0 +1,49 @@
1
+ module Delayed
2
+ module Plugins
3
+ ##
4
+ # Provides integration with Delayed Job.
5
+ # rubocop:disable Lint/RescueException
6
+ class Airbrake < ::Delayed::Plugin
7
+ callbacks do |lifecycle|
8
+ lifecycle.around(:invoke_job) do |job, *args, &block|
9
+ begin
10
+ # Forward the call to the next callback in the callback chain
11
+ block.call(job, *args)
12
+ rescue Exception => exception
13
+ params = job.as_json
14
+
15
+ # If DelayedJob is used through ActiveJob, it contains extra info.
16
+ if job.payload_object.respond_to?(:job_data)
17
+ params[:active_job] = job.payload_object.job_data
18
+ end
19
+
20
+ ::Airbrake.notify(exception, params) do |notice|
21
+ notice[:context][:component] = 'delayed_job'
22
+ notice[:context][:action] = job.payload_object.class.name
23
+ end
24
+
25
+ raise exception
26
+ end
27
+ end
28
+ end
29
+ end
30
+ # rubocop:enable Lint/RescueException
31
+ end
32
+ end
33
+
34
+ if RUBY_ENGINE == 'jruby' && defined?(Delayed::Backend::ActiveRecord::Job)
35
+ ##
36
+ # Workaround against JRuby bug:
37
+ # https://github.com/jruby/jruby/issues/3338
38
+ # rubocop:disable Style/ClassAndModuleChildren
39
+ class Delayed::Backend::ActiveRecord::Job
40
+ alias old_to_ary to_ary
41
+
42
+ def to_ary
43
+ old_to_ary || [self]
44
+ end
45
+ end
46
+ # rubocop:enable Style/ClassAndModuleChildren
47
+ end
48
+
49
+ Delayed::Worker.plugins << Delayed::Plugins::Airbrake
@@ -1,51 +1,5 @@
1
- module Delayed
2
- module Plugins
3
- ##
4
- # Provides integration with Delayed Job.
5
- # rubocop:disable Lint/RescueException
6
- class Airbrake < ::Delayed::Plugin
7
- callbacks do |lifecycle|
8
- lifecycle.around(:invoke_job) do |job, *args, &block|
9
- begin
10
- # Forward the call to the next callback in the callback chain
11
- block.call(job, *args)
12
- rescue Exception => exception
13
- params = job.as_json
1
+ require 'airbrake/delayed_job'
14
2
 
15
- # If DelayedJob is used through ActiveJob, it contains extra info.
16
- if job.payload_object.respond_to?(:job_data)
17
- params[:active_job] = job.payload_object.job_data
18
- end
19
-
20
- if (notice = ::Airbrake.build_notice(exception, params))
21
- notice[:context][:component] = 'delayed_job'
22
- notice[:context][:action] = job.payload_object.class.name
23
-
24
- ::Airbrake.notify(notice)
25
- end
26
-
27
- raise exception
28
- end
29
- end
30
- end
31
- end
32
- # rubocop:enable Lint/RescueException
33
- end
34
- end
35
-
36
- if RUBY_ENGINE == 'jruby' && defined?(Delayed::Backend::ActiveRecord::Job)
37
- ##
38
- # Workaround against JRuby bug:
39
- # https://github.com/jruby/jruby/issues/3338
40
- # rubocop:disable Style/ClassAndModuleChildren
41
- class Delayed::Backend::ActiveRecord::Job
42
- alias old_to_ary to_ary
43
-
44
- def to_ary
45
- old_to_ary || [self]
46
- end
47
- end
48
- # rubocop:enable Style/ClassAndModuleChildren
49
- end
50
-
51
- Delayed::Worker.plugins << Delayed::Plugins::Airbrake
3
+ warn "DEPRECATION WARNING: Requiring 'airbrake/delayed_job/plugin' is " \
4
+ "deprecated and will be removed in the next MAJOR release. Require " \
5
+ "'airbrake/delayed_job' instead."
@@ -0,0 +1,102 @@
1
+ require 'logger'
2
+
3
+ module Airbrake
4
+ ##
5
+ # Decorator for +Logger+ from stdlib. Endows loggers the ability to both log
6
+ # and report errors to Airbrake.
7
+ #
8
+ # @example
9
+ # # Create a logger like you normally do and decorate it.
10
+ # logger = Airbrake::AirbrakeLogger.new(Logger.new(STDOUT))
11
+ #
12
+ # # Just use the logger like you normally do.
13
+ # logger.fatal('oops')
14
+ class AirbrakeLogger < SimpleDelegator
15
+ ##
16
+ # @example
17
+ # # Assign a default Airbrake notifier
18
+ # logger.airbrake_notifier = Airbrake[:default]
19
+ # @return [Airbrake::Notifier] notifier to be used to send notices
20
+ attr_accessor :airbrake_notifier
21
+
22
+ ##
23
+ # @return [Integer]
24
+ attr_reader :airbrake_level
25
+
26
+ def initialize(logger)
27
+ __setobj__(logger)
28
+ @airbrake_notifier = Airbrake[:default]
29
+ @airbrake_level = Logger::WARN
30
+ end
31
+
32
+ ##
33
+ # @see Logger#warn
34
+ def warn(progname = nil, &block)
35
+ notify_airbrake(Logger::WARN, progname)
36
+ super
37
+ end
38
+
39
+ ##
40
+ # @see Logger#error
41
+ def error(progname = nil, &block)
42
+ notify_airbrake(Logger::ERROR, progname)
43
+ super
44
+ end
45
+
46
+ ##
47
+ # @see Logger#fatal
48
+ def fatal(progname = nil, &block)
49
+ notify_airbrake(Logger::FATAL, progname)
50
+ super
51
+ end
52
+
53
+ ##
54
+ # @see Logger#unknown
55
+ def unknown(progname = nil, &block)
56
+ notify_airbrake(Logger::UNKNOWN, progname)
57
+ super
58
+ end
59
+
60
+ ##
61
+ # Sets airbrake severity level. Does not permit values below `Logger::WARN`.
62
+ #
63
+ # @example
64
+ # logger.airbrake_level = Logger::FATAL
65
+ # @return [void]
66
+ def airbrake_level=(level)
67
+ if level < Logger::WARN
68
+ raise "Airbrake severity level #{level} is not allowed. " \
69
+ "Minimum allowed level is #{Logger::WARN}"
70
+ end
71
+ @airbrake_level = level
72
+ end
73
+
74
+ private
75
+
76
+ def notify_airbrake(severity, progname)
77
+ return if severity < @airbrake_level || !@airbrake_notifier
78
+
79
+ @airbrake_notifier.notify(progname) do |notice|
80
+ # Get rid of unwanted internal Logger frames. Examples:
81
+ # * /ruby-2.4.0/lib/ruby/2.4.0/logger.rb
82
+ # * /gems/activesupport-4.2.7.1/lib/active_support/logger.rb
83
+ backtrace = notice[:errors].first[:backtrace]
84
+ notice[:errors].first[:backtrace] =
85
+ backtrace.drop_while { |frame| frame[:file] =~ %r{/logger.rb\z} }
86
+
87
+ notice[:context][:component] = 'log'
88
+ notice[:context][:severity] = normalize_severity(severity)
89
+ end
90
+ end
91
+
92
+ def normalize_severity(severity)
93
+ (case severity
94
+ when Logger::WARN then 'warning'
95
+ when Logger::ERROR, Logger::UNKNOWN then 'error'
96
+ when Logger::FATAL then 'critical'
97
+ else
98
+ raise "Unknown airbrake severity: #{severity}"
99
+ end).freeze
100
+ end
101
+ end
102
+ end
@@ -1,106 +1,5 @@
1
- require 'logger'
1
+ require 'airbrake/logger'
2
2
 
3
- module Airbrake
4
- ##
5
- # Decorator for +Logger+ from stdlib. Endows loggers the ability to both log
6
- # and report errors to Airbrake.
7
- #
8
- # @example
9
- # # Create a logger like you normally do and decorate it.
10
- # logger = Airbrake::AirbrakeLogger.new(Logger.new(STDOUT))
11
- #
12
- # # Just use the logger like you normally do.
13
- # logger.fatal('oops')
14
- class AirbrakeLogger < SimpleDelegator
15
- ##
16
- # @example
17
- # # Assign a default Airbrake notifier
18
- # logger.airbrake_notifier = Airbrake[:default]
19
- # @return [Airbrake::Notifier] notifier to be used to send notices
20
- attr_accessor :airbrake_notifier
21
-
22
- ##
23
- # @example
24
- # logger.airbrake_level = Logger::FATAL
25
- # @return [Integer]
26
- attr_accessor :airbrake_level
27
-
28
- def initialize(logger)
29
- __setobj__(logger)
30
- @airbrake_notifier = Airbrake[:default]
31
- @airbrake_level = Logger::WARN
32
- end
33
-
34
- ##
35
- # @see Logger#warn
36
- def warn(progname = nil, &block)
37
- notify_airbrake(Logger::WARN, progname)
38
- super
39
- end
40
-
41
- ##
42
- # @see Logger#error
43
- def error(progname = nil, &block)
44
- notify_airbrake(Logger::ERROR, progname)
45
- super
46
- end
47
-
48
- ##
49
- # @see Logger#fatal
50
- def fatal(progname = nil, &block)
51
- notify_airbrake(Logger::FATAL, progname)
52
- super
53
- end
54
-
55
- ##
56
- # @see Logger#unknown
57
- def unknown(progname = nil, &block)
58
- notify_airbrake(Logger::UNKNOWN, progname)
59
- super
60
- end
61
-
62
- ##
63
- # Sets airbrake severity level. Does not permit values below `Logger::WARN`.
64
- #
65
- # @example
66
- # logger.airbrake_level = Logger::FATAL
67
- # @return [void]
68
- def airbrake_level=(level)
69
- if level < Logger::WARN
70
- raise "Airbrake severity level #{level} is not allowed. " \
71
- "Minimum allowed level is #{Logger::WARN}"
72
- end
73
- @airbrake_level = level
74
- end
75
-
76
- private
77
-
78
- def notify_airbrake(severity, progname)
79
- return if severity < @airbrake_level || !@airbrake_notifier
80
-
81
- notice = @airbrake_notifier.build_notice(progname)
82
-
83
- # Get rid of unwanted internal Logger frames. Examples:
84
- # * /ruby-2.4.0/lib/ruby/2.4.0/logger.rb
85
- # * /gems/activesupport-4.2.7.1/lib/active_support/logger.rb
86
- backtrace = notice[:errors].first[:backtrace]
87
- notice[:errors].first[:backtrace] =
88
- backtrace.drop_while { |frame| frame[:file] =~ %r{/logger.rb\z} }
89
-
90
- notice[:context][:component] = 'log'
91
- notice[:context][:severity] = normalize_severity(severity)
92
-
93
- @airbrake_notifier.notify(notice)
94
- end
95
-
96
- def normalize_severity(severity)
97
- (case severity
98
- when Logger::WARN then 'warning'
99
- when Logger::ERROR, Logger::UNKNOWN then 'error'
100
- when Logger::FATAL then 'critical'
101
- else
102
- raise "Unknown airbrake severity: #{severity}"
103
- end).freeze
104
- end
105
- end
106
- end
3
+ warn "DEPRECATION WARNING: Requiring 'airbrake/logger/airbrake_logger' is " \
4
+ "deprecated and will be removed in the next MAJOR release. Require " \
5
+ "'airbrake/logger' instead."
@@ -0,0 +1,7 @@
1
+ require 'airbrake/rack/user'
2
+ require 'airbrake/rack/context_filter'
3
+ require 'airbrake/rack/session_filter'
4
+ require 'airbrake/rack/http_params_filter'
5
+ require 'airbrake/rack/http_headers_filter'
6
+ require 'airbrake/rack/request_body_filter'
7
+ require 'airbrake/rack/middleware'
@@ -5,6 +5,10 @@ module Airbrake
5
5
  #
6
6
  # @since v5.7.0
7
7
  class ContextFilter
8
+ ##
9
+ # @return [Integer]
10
+ attr_reader :weight
11
+
8
12
  def initialize
9
13
  @framework_version =
10
14
  if defined?(::Rails) && ::Rails.respond_to?(:version)
@@ -14,6 +18,7 @@ module Airbrake
14
18
  else
15
19
  "Rack.version/#{::Rack.version} Rack.release/#{::Rack.release}"
16
20
  end.freeze
21
+ @weight = 99
17
22
  end
18
23
 
19
24
  ##
@@ -14,6 +14,14 @@ module Airbrake
14
14
  'CONTENT_LENGTH'.freeze
15
15
  ].freeze
16
16
 
17
+ ##
18
+ # @return [Integer]
19
+ attr_reader :weight
20
+
21
+ def initialize
22
+ @weight = 98
23
+ end
24
+
17
25
  ##
18
26
  # @see {Airbrake::FilterChain#refine}
19
27
  def call(notice)
@@ -27,7 +35,7 @@ module Airbrake
27
35
  headers
28
36
  end
29
37
 
30
- notice[:environment].merge!(
38
+ notice[:context].merge!(
31
39
  httpMethod: request.request_method,
32
40
  referer: request.referer,
33
41
  headers: http_headers
@@ -5,12 +5,20 @@ module Airbrake
5
5
  #
6
6
  # @since v5.7.0
7
7
  class HttpParamsFilter
8
+ ##
9
+ # @return [Integer]
10
+ attr_reader :weight
11
+
12
+ def initialize
13
+ @weight = 97
14
+ end
15
+
8
16
  ##
9
17
  # @see {Airbrake::FilterChain#refine}
10
18
  def call(notice)
11
19
  return unless (request = notice.stash[:rack_request])
12
20
 
13
- notice[:params] = request.params
21
+ notice[:params].merge!(request.params)
14
22
 
15
23
  rails_params = request.env['action_dispatch.request.parameters']
16
24
  notice[:params].merge!(rails_params) if rails_params
@@ -10,10 +10,15 @@ module Airbrake
10
10
  # @since v5.7.0
11
11
  # @note This filter is *not* used by default.
12
12
  class RequestBodyFilter
13
+ ##
14
+ # @return [Integer]
15
+ attr_reader :weight
16
+
13
17
  ##
14
18
  # @param [Integer] length The maximum number of bytes to read
15
19
  def initialize(length = 4096)
16
20
  @length = length
21
+ @weight = 95
17
22
  end
18
23
 
19
24
  ##