honeybadger 1.16.7 → 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (200) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +19 -0
  3. data/README.md +37 -16
  4. data/bin/honeybadger +5 -0
  5. data/lib/honeybadger.rb +167 -191
  6. data/lib/honeybadger/agent.rb +136 -0
  7. data/lib/honeybadger/backend.rb +26 -0
  8. data/lib/honeybadger/backend/base.rb +66 -0
  9. data/lib/honeybadger/backend/debug.rb +12 -0
  10. data/lib/honeybadger/backend/null.rb +16 -0
  11. data/lib/honeybadger/backend/server.rb +51 -0
  12. data/lib/honeybadger/backend/test.rb +24 -0
  13. data/lib/honeybadger/backtrace.rb +29 -24
  14. data/lib/honeybadger/cli.rb +367 -0
  15. data/lib/honeybadger/config.rb +333 -0
  16. data/lib/honeybadger/config/callbacks.rb +70 -0
  17. data/lib/honeybadger/config/defaults.rb +175 -0
  18. data/lib/honeybadger/config/env.rb +40 -0
  19. data/lib/honeybadger/config/yaml.rb +43 -0
  20. data/lib/honeybadger/const.rb +28 -0
  21. data/lib/honeybadger/init/rails.rb +84 -0
  22. data/lib/honeybadger/init/sinatra.rb +27 -0
  23. data/lib/honeybadger/logging.rb +133 -0
  24. data/lib/honeybadger/notice.rb +243 -280
  25. data/lib/honeybadger/plugin.rb +110 -0
  26. data/lib/honeybadger/plugins/delayed_job.rb +22 -0
  27. data/lib/honeybadger/{integrations → plugins}/delayed_job/plugin.rb +6 -7
  28. data/lib/honeybadger/{integrations → plugins}/local_variables.rb +7 -8
  29. data/lib/honeybadger/{integrations → plugins}/net_http.rb +10 -8
  30. data/lib/honeybadger/plugins/passenger.rb +24 -0
  31. data/lib/honeybadger/plugins/rails.rb +61 -0
  32. data/lib/honeybadger/plugins/sidekiq.rb +35 -0
  33. data/lib/honeybadger/{integrations → plugins}/thor.rb +9 -8
  34. data/lib/honeybadger/{integrations → plugins}/unicorn.rb +10 -9
  35. data/lib/honeybadger/rack/error_notifier.rb +44 -27
  36. data/lib/honeybadger/rack/metrics_reporter.rb +41 -0
  37. data/lib/honeybadger/rack/request_hash.rb +50 -0
  38. data/lib/honeybadger/rack/user_feedback.rb +15 -10
  39. data/lib/honeybadger/rack/user_informer.rb +14 -3
  40. data/lib/honeybadger/trace.rb +185 -0
  41. data/lib/honeybadger/util/http.rb +79 -0
  42. data/lib/honeybadger/util/request_sanitizer.rb +35 -0
  43. data/lib/honeybadger/util/sanitizer.rb +71 -0
  44. data/lib/honeybadger/util/stats.rb +31 -0
  45. data/lib/honeybadger/version.rb +4 -0
  46. data/lib/honeybadger/worker.rb +224 -0
  47. data/lib/honeybadger/worker/batch.rb +50 -0
  48. data/lib/honeybadger/worker/metered_queue.rb +80 -0
  49. data/lib/honeybadger/worker/metrics_collection.rb +61 -0
  50. data/lib/honeybadger/worker/metrics_collector.rb +96 -0
  51. data/{lib/honeybadger/capistrano.rb → vendor/capistrano-honeybadger/lib/capistrano/honeybadger.rb} +1 -3
  52. data/vendor/capistrano-honeybadger/lib/capistrano/tasks/deploy.cap +76 -0
  53. data/vendor/capistrano-honeybadger/lib/honeybadger/capistrano.rb +2 -0
  54. data/{lib → vendor/capistrano-honeybadger/lib}/honeybadger/capistrano/legacy.rb +16 -15
  55. data/vendor/thor/lib/thor.rb +484 -0
  56. data/vendor/thor/lib/thor/actions.rb +319 -0
  57. data/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  58. data/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  59. data/vendor/thor/lib/thor/actions/directory.rb +118 -0
  60. data/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  61. data/vendor/thor/lib/thor/actions/file_manipulation.rb +316 -0
  62. data/vendor/thor/lib/thor/actions/inject_into_file.rb +107 -0
  63. data/vendor/thor/lib/thor/base.rb +656 -0
  64. data/vendor/thor/lib/thor/command.rb +133 -0
  65. data/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  66. data/vendor/thor/lib/thor/core_ext/io_binary_read.rb +10 -0
  67. data/vendor/thor/lib/thor/core_ext/ordered_hash.rb +98 -0
  68. data/vendor/thor/lib/thor/error.rb +32 -0
  69. data/vendor/thor/lib/thor/group.rb +281 -0
  70. data/vendor/thor/lib/thor/invocation.rb +178 -0
  71. data/vendor/thor/lib/thor/line_editor.rb +17 -0
  72. data/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  73. data/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  74. data/vendor/thor/lib/thor/parser.rb +4 -0
  75. data/vendor/thor/lib/thor/parser/argument.rb +73 -0
  76. data/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  77. data/vendor/thor/lib/thor/parser/option.rb +125 -0
  78. data/vendor/thor/lib/thor/parser/options.rb +218 -0
  79. data/vendor/thor/lib/thor/rake_compat.rb +71 -0
  80. data/vendor/thor/lib/thor/runner.rb +322 -0
  81. data/vendor/thor/lib/thor/shell.rb +81 -0
  82. data/vendor/thor/lib/thor/shell/basic.rb +421 -0
  83. data/vendor/thor/lib/thor/shell/color.rb +149 -0
  84. data/vendor/thor/lib/thor/shell/html.rb +126 -0
  85. data/vendor/thor/lib/thor/util.rb +267 -0
  86. data/vendor/thor/lib/thor/version.rb +3 -0
  87. metadata +97 -305
  88. data/Appraisals +0 -95
  89. data/CHANGELOG.md +0 -422
  90. data/Gemfile +0 -8
  91. data/Gemfile.lock +0 -136
  92. data/Guardfile +0 -5
  93. data/MIT-LICENSE +0 -32
  94. data/Rakefile +0 -159
  95. data/features/metal.feature +0 -20
  96. data/features/rack.feature +0 -55
  97. data/features/rails.feature +0 -343
  98. data/features/rails3.x.feature +0 -26
  99. data/features/rake.feature +0 -25
  100. data/features/sinatra.feature +0 -27
  101. data/features/standalone.feature +0 -73
  102. data/features/step_definitions/metal_steps.rb +0 -24
  103. data/features/step_definitions/rack_steps.rb +0 -18
  104. data/features/step_definitions/rails_steps.rb +0 -270
  105. data/features/step_definitions/rake_steps.rb +0 -17
  106. data/features/step_definitions/standalone_steps.rb +0 -12
  107. data/features/step_definitions/thor_steps.rb +0 -4
  108. data/features/support/env.rb +0 -22
  109. data/features/support/honeybadger_failure_shim.rb.template +0 -5
  110. data/features/support/honeybadger_shim.rb.template +0 -6
  111. data/features/support/rails.rb +0 -202
  112. data/features/support/rake/Rakefile +0 -68
  113. data/features/support/test.thor +0 -22
  114. data/features/thor.feature +0 -5
  115. data/gemfiles/binding_of_caller.gemfile +0 -13
  116. data/gemfiles/delayed_job.gemfile +0 -13
  117. data/gemfiles/rack.gemfile +0 -13
  118. data/gemfiles/rails.gemfile +0 -16
  119. data/gemfiles/rails2.3.gemfile +0 -15
  120. data/gemfiles/rails3.0.gemfile +0 -16
  121. data/gemfiles/rails3.1.gemfile +0 -16
  122. data/gemfiles/rails3.2.gemfile +0 -16
  123. data/gemfiles/rails4.0.gemfile +0 -16
  124. data/gemfiles/rails4.1.gemfile +0 -16
  125. data/gemfiles/rake.gemfile +0 -13
  126. data/gemfiles/sinatra.gemfile +0 -13
  127. data/gemfiles/standalone.gemfile +0 -12
  128. data/gemfiles/thor.gemfile +0 -13
  129. data/generators/honeybadger/honeybadger_generator.rb +0 -95
  130. data/generators/honeybadger/lib/insert_commands.rb +0 -34
  131. data/generators/honeybadger/lib/rake_commands.rb +0 -24
  132. data/generators/honeybadger/templates/capistrano_hook.rb +0 -6
  133. data/generators/honeybadger/templates/honeybadger_tasks.rake +0 -25
  134. data/generators/honeybadger/templates/initializer.rb +0 -6
  135. data/honeybadger.gemspec +0 -174
  136. data/lib/honeybadger/array.rb +0 -53
  137. data/lib/honeybadger/capistrano/tasks.rake +0 -73
  138. data/lib/honeybadger/configuration.rb +0 -397
  139. data/lib/honeybadger/dependency.rb +0 -65
  140. data/lib/honeybadger/integrations.rb +0 -9
  141. data/lib/honeybadger/integrations/delayed_job.rb +0 -20
  142. data/lib/honeybadger/integrations/passenger.rb +0 -18
  143. data/lib/honeybadger/integrations/sidekiq.rb +0 -37
  144. data/lib/honeybadger/monitor.rb +0 -17
  145. data/lib/honeybadger/monitor/railtie.rb +0 -53
  146. data/lib/honeybadger/monitor/sender.rb +0 -44
  147. data/lib/honeybadger/monitor/trace.rb +0 -187
  148. data/lib/honeybadger/monitor/worker.rb +0 -169
  149. data/lib/honeybadger/payload.rb +0 -101
  150. data/lib/honeybadger/rack.rb +0 -12
  151. data/lib/honeybadger/rails.rb +0 -45
  152. data/lib/honeybadger/rails/action_controller_catcher.rb +0 -30
  153. data/lib/honeybadger/rails/controller_methods.rb +0 -78
  154. data/lib/honeybadger/rails/middleware/exceptions_catcher.rb +0 -29
  155. data/lib/honeybadger/rails3_tasks.rb +0 -94
  156. data/lib/honeybadger/railtie.rb +0 -52
  157. data/lib/honeybadger/rake_handler.rb +0 -66
  158. data/lib/honeybadger/sender.rb +0 -185
  159. data/lib/honeybadger/shared_tasks.rb +0 -56
  160. data/lib/honeybadger/stats.rb +0 -29
  161. data/lib/honeybadger/tasks.rb +0 -95
  162. data/lib/honeybadger/user_feedback.rb +0 -8
  163. data/lib/honeybadger/user_informer.rb +0 -8
  164. data/lib/honeybadger_tasks.rb +0 -69
  165. data/lib/rails/generators/honeybadger/honeybadger_generator.rb +0 -99
  166. data/rails/init.rb +0 -1
  167. data/resources/README.md +0 -34
  168. data/script/integration_test.rb +0 -38
  169. data/spec/allocation_stats.rb +0 -32
  170. data/spec/honeybadger/backtrace_spec.rb +0 -242
  171. data/spec/honeybadger/capistrano_spec.rb +0 -36
  172. data/spec/honeybadger/configuration_spec.rb +0 -328
  173. data/spec/honeybadger/dependency_spec.rb +0 -134
  174. data/spec/honeybadger/integrations/delayed_job_spec.rb +0 -82
  175. data/spec/honeybadger/integrations/local_variables_spec.rb +0 -60
  176. data/spec/honeybadger/integrations/net_http_spec.rb +0 -29
  177. data/spec/honeybadger/integrations/passenger_spec.rb +0 -29
  178. data/spec/honeybadger/integrations/sidekiq_spec.rb +0 -60
  179. data/spec/honeybadger/integrations/thor_spec.rb +0 -32
  180. data/spec/honeybadger/integrations/unicorn_spec.rb +0 -40
  181. data/spec/honeybadger/logger_spec.rb +0 -79
  182. data/spec/honeybadger/monitor/trace_spec.rb +0 -65
  183. data/spec/honeybadger/monitor/worker_spec.rb +0 -274
  184. data/spec/honeybadger/notice_spec.rb +0 -669
  185. data/spec/honeybadger/notifier_spec.rb +0 -328
  186. data/spec/honeybadger/payload_spec.rb +0 -162
  187. data/spec/honeybadger/rack_spec.rb +0 -85
  188. data/spec/honeybadger/rails/action_controller_spec.rb +0 -328
  189. data/spec/honeybadger/rails_spec.rb +0 -37
  190. data/spec/honeybadger/sender_spec.rb +0 -317
  191. data/spec/honeybadger/stats_spec.rb +0 -57
  192. data/spec/honeybadger/user_feedback_spec.rb +0 -80
  193. data/spec/honeybadger/user_informer_spec.rb +0 -30
  194. data/spec/honeybadger_tasks_spec.rb +0 -171
  195. data/spec/spec_helper.rb +0 -24
  196. data/spec/support/array_including.rb +0 -31
  197. data/spec/support/backtraced_exception.rb +0 -9
  198. data/spec/support/collected_sender.rb +0 -12
  199. data/spec/support/defines_constants.rb +0 -18
  200. data/spec/support/helpers.rb +0 -101
@@ -0,0 +1,110 @@
1
+ require 'forwardable'
2
+
3
+ module Honeybadger
4
+ class Plugin
5
+ CALLER_FILE = Regexp.new('\A([^:]+)(?=(:\d+))').freeze
6
+
7
+ class << self
8
+ @@instances = {}
9
+
10
+ def instances
11
+ @@instances
12
+ end
13
+
14
+ def register(name = nil)
15
+ name ||= name_from_caller(caller) or
16
+ raise(ArgumentError, 'Plugin name is required, but was nil.')
17
+ instances[key = name.to_sym] and fail("Already registered: #{name}")
18
+ instances[key] = new(name).tap { |d| d.instance_eval(&Proc.new) }
19
+ end
20
+
21
+ def load!(config)
22
+ instances.each_pair do |name, plugin|
23
+ if config.load_plugin?(name)
24
+ plugin.load!(config)
25
+ else
26
+ config.logger.debug(sprintf('skip plugin name=%s reason=disabled', name))
27
+ end
28
+ end
29
+ end
30
+
31
+ def name_from_caller(caller)
32
+ caller && caller[0].match(CALLER_FILE) or
33
+ fail("Unable to determine name from caller: #{caller.inspect}")
34
+ File.basename($1)[/[^\.]+/]
35
+ end
36
+ end
37
+
38
+ class Execution
39
+ extend Forwardable
40
+
41
+ def initialize(config, &block)
42
+ @config = config
43
+ @block = block
44
+ end
45
+
46
+ def call
47
+ instance_eval(&block)
48
+ end
49
+
50
+ private
51
+
52
+ attr_reader :config, :block
53
+ def_delegator :@config, :logger
54
+ end
55
+
56
+ def initialize(name)
57
+ @name = name
58
+ @loaded = false
59
+ @requirements = []
60
+ @executions = []
61
+ end
62
+
63
+ def requirement
64
+ @requirements << Proc.new
65
+ end
66
+
67
+ def execution
68
+ @executions << Proc.new
69
+ end
70
+
71
+ def ok?(config)
72
+ @requirements.all? {|r| Execution.new(config, &r).call }
73
+ rescue => e
74
+ config.logger.error(sprintf('plugin error name=%s class=%s message=%s location=%s', name, e.class, e.message.dump, e.backtrace.first.dump))
75
+ false
76
+ end
77
+
78
+ def load!(config)
79
+ if @loaded
80
+ config.logger.debug(sprintf('skip plugin name=%s reason=loaded', name))
81
+ return false
82
+ elsif ok?(config)
83
+ config.logger.debug(sprintf('load plugin name=%s', name))
84
+ @executions.each {|e| Execution.new(config, &e).call }
85
+ @loaded = true
86
+ else
87
+ config.logger.debug(sprintf('skip plugin name=%s reason=requirement', name))
88
+ end
89
+
90
+ @loaded
91
+ rescue => e
92
+ config.logger.error(sprintf('plugin error name=%s class=%s message=%s location=%s', name, e.class, e.message.dump, e.backtrace.first.dump))
93
+ @loaded = true
94
+ false
95
+ end
96
+
97
+ # Private: Used for testing only; don't normally call this. :)
98
+ #
99
+ # Returns nothing
100
+ def reset!
101
+ @loaded = false
102
+ end
103
+
104
+ def loaded?
105
+ @loaded
106
+ end
107
+
108
+ attr_reader :name, :requirements, :executions
109
+ end
110
+ end
@@ -0,0 +1,22 @@
1
+ require 'honeybadger/plugin'
2
+
3
+ module Honeybadger
4
+ Plugin.register do
5
+ requirement { defined?(::Delayed::Plugin) }
6
+ requirement { defined?(::Delayed::Worker.plugins) }
7
+ requirement do
8
+ if delayed_job_honeybadger = defined?(::Delayed::Plugins::Honeybadger)
9
+ logger.warn("Support for Delayed Job has been moved " \
10
+ "to the honeybadger gem. Please remove " \
11
+ "delayed_job_honeybadger from your " \
12
+ "Gemfile.")
13
+ end
14
+ !delayed_job_honeybadger
15
+ end
16
+
17
+ execution do
18
+ require 'honeybadger/plugins/delayed_job/plugin'
19
+ ::Delayed::Worker.plugins << Plugins::DelayedJob::Plugin
20
+ end
21
+ end
22
+ end
@@ -1,15 +1,14 @@
1
+ require 'delayed_job'
2
+ require 'honeybadger'
3
+
1
4
  module Honeybadger
2
- module Integrations
5
+ module Plugins
3
6
  module DelayedJob
4
7
  class Plugin < ::Delayed::Plugin
5
8
  callbacks do |lifecycle|
6
9
  lifecycle.around(:invoke_job) do |job, &block|
7
10
  begin
8
- if defined?(::Honeybadger::Monitor)
9
- ::Honeybadger::Monitor::Trace.instrument("#{job.payload_object.class}#perform", { :source => 'delayed_job', :jid => job.id, :class => job.payload_object.class.name }) do
10
- block.call(job)
11
- end
12
- else
11
+ ::Honeybadger::Trace.instrument("#{job.payload_object.class}#perform", {source: 'delayed_job', jid: job.id, class: job.payload_object.class.name}) do
13
12
  block.call(job)
14
13
  end
15
14
  rescue Exception => error
@@ -24,7 +23,7 @@ module Honeybadger
24
23
  :attempts => job.attempts,
25
24
  :queue => job.queue
26
25
  }
27
- ) if job.attempts.to_i >= ::Honeybadger.configuration.delayed_job_attempt_threshold.to_i
26
+ )
28
27
  raise error
29
28
  ensure
30
29
  ::Honeybadger.context.clear!
@@ -1,5 +1,8 @@
1
+ require 'honeybadger/plugin'
2
+ require 'honeybadger/backtrace'
3
+
1
4
  module Honeybadger
2
- module Integrations
5
+ module Plugins
3
6
  module LocalVariables
4
7
  module ExceptionExtension
5
8
  def self.included(base)
@@ -20,16 +23,12 @@ module Honeybadger
20
23
  end
21
24
  end
22
25
 
23
- Dependency.register do
24
- requirement { ::Honeybadger.configuration.send_local_variables }
26
+ Plugin.register do
27
+ requirement { config[:'exceptions.local_variables'] }
25
28
  requirement { defined?(::BindingOfCaller) }
26
29
  requirement { !::Exception.included_modules.include?(ExceptionExtension) }
27
30
 
28
- injection { Honeybadger.write_verbose_log('Installing local variables integration') }
29
-
30
- injection do
31
- ::Exception.send(:include, ExceptionExtension)
32
- end
31
+ execution { ::Exception.send(:include, ExceptionExtension) }
33
32
  end
34
33
  end
35
34
  end
@@ -1,5 +1,7 @@
1
+ require 'honeybadger/plugin'
2
+
1
3
  module Honeybadger
2
- module Integrations
4
+ module Plugins
3
5
  module NetHttp
4
6
  module Instrumentation
5
7
  def self.included(base)
@@ -20,14 +22,14 @@ module Honeybadger
20
22
  end
21
23
  end
22
24
  end
23
- end
24
- end
25
25
 
26
- Dependency.register do
27
- requirement { defined?(::ActiveSupport::Notifications) }
28
- requirement { defined?(::Net::HTTP) }
29
- requirement { defined?(::Honeybadger::Monitor) }
26
+ Plugin.register do
27
+ requirement { defined?(::ActiveSupport::Notifications) }
28
+ requirement { defined?(::Net::HTTP) }
29
+ requirement { config[:'traces.enabled'] }
30
30
 
31
- injection { ::Net::HTTP.send(:include, Integrations::NetHttp::Instrumentation) }
31
+ execution { ::Net::HTTP.send(:include, Instrumentation) }
32
+ end
33
+ end
32
34
  end
33
35
  end
@@ -0,0 +1,24 @@
1
+ require 'honeybadger/plugin'
2
+ require 'honeybadger/agent'
3
+
4
+ module Honeybadger
5
+ module Plugins
6
+ module Passenger
7
+ Plugin.register do
8
+ requirement { defined?(::PhusionPassenger) }
9
+
10
+ execution do
11
+ ::PhusionPassenger.on_event(:starting_worker_process) do |forked|
12
+ logger.debug('Starting passenger worker process')
13
+ Honeybadger::Agent.fork if forked
14
+ end
15
+
16
+ ::PhusionPassenger.on_event(:stopping_worker_process) do
17
+ logger.debug('Stopping passenger worker process')
18
+ Honeybadger::Agent.stop
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,61 @@
1
+ require 'honeybadger/plugin'
2
+
3
+ module Honeybadger
4
+ module Plugins
5
+ module Rails
6
+ module ExceptionsCatcher
7
+ def self.included(base)
8
+ base.send(:alias_method, :render_exception_without_honeybadger, :render_exception)
9
+ base.send(:alias_method, :render_exception, :render_exception_with_honeybadger)
10
+ end
11
+
12
+ def render_exception_with_honeybadger(env, exception)
13
+ env['honeybadger.exception'] = exception
14
+ render_exception_without_honeybadger(env,exception)
15
+ end
16
+ end
17
+
18
+ module ControllerMethods
19
+ def honeybadger_request_data
20
+ warn('#honeybadger_request_data has been deprecated and has no effect.')
21
+ {}
22
+ end
23
+
24
+ def notify_honeybadger(*args, &block)
25
+ warn('#notify_honeybadger has been deprecated; please use `Honeybadger.notify`.')
26
+ Honeybadger.notify(*args, &block)
27
+ end
28
+
29
+ def notify_honeybadger_or_ignore(*args, &block)
30
+ warn('#notify_honeybadger_or_ignore has been deprecated; please use `Honeybadger.notify`.')
31
+ Honeybadger.notify(*args, &block)
32
+ end
33
+ end
34
+
35
+ Plugin.register :rails_controller_methods do
36
+ requirement { defined?(::Rails) }
37
+
38
+ execution do
39
+ ActiveSupport.on_load(:action_controller) do
40
+ # Lazily load action_controller methods
41
+ include ::Honeybadger::Plugins::Rails::ControllerMethods
42
+ end
43
+ end
44
+ end
45
+
46
+ Plugin.register :rails_exceptions_catcher do
47
+ requirement { defined?(::Rails) }
48
+
49
+ execution do
50
+ if defined?(::ActionDispatch::DebugExceptions)
51
+ # Rails 3.2.x+
52
+ ::ActionDispatch::DebugExceptions.send(:include, ExceptionsCatcher)
53
+ elsif defined?(::ActionDispatch::ShowExceptions)
54
+ # Rails 3.0.x and 3.1.x
55
+ ::ActionDispatch::ShowExceptions.send(:include, ExceptionsCatcher)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,35 @@
1
+ require 'honeybadger/plugin'
2
+ require 'honeybadger'
3
+
4
+ module Honeybadger
5
+ module Plugins
6
+ module Sidekiq
7
+ class Middleware
8
+ def call(worker, msg, queue)
9
+ Honeybadger.context.clear!
10
+ Honeybadger::Trace.instrument("#{msg['class']}#perform", { :source => 'sidekiq', :jid => msg['jid'], :class => msg['class'] }) do
11
+ yield
12
+ end
13
+ end
14
+ end
15
+
16
+ Plugin.register do
17
+ requirement { defined?(::Sidekiq) }
18
+
19
+ execution do
20
+ ::Sidekiq.configure_server do |config|
21
+ config.server_middleware do |chain|
22
+ chain.add Middleware
23
+ end
24
+ end
25
+
26
+ if defined?(::Sidekiq::VERSION) && ::Sidekiq::VERSION > '3'
27
+ ::Sidekiq.configure_server do |config|
28
+ config.error_handlers << Proc.new {|ex,context| Honeybadger.notify_or_ignore(ex, parameters: context) }
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,8 @@
1
+ require 'honeybadger/plugin'
2
+ require 'honeybadger'
3
+
1
4
  module Honeybadger
2
- module Integrations
5
+ module Plugins
3
6
  module Thor
4
7
  def self.included(base)
5
8
  base.class_eval do
@@ -17,15 +20,13 @@ module Honeybadger
17
20
  raise
18
21
  end
19
22
  end
20
- end
21
23
 
22
- Dependency.register do
23
- requirement { defined?(::Thor.no_commands) }
24
+ Plugin.register do
25
+ requirement { defined?(::Thor.no_commands) }
24
26
 
25
- injection { Honeybadger.write_verbose_log('Installing Thor integration') }
26
-
27
- injection do
28
- ::Thor.send(:include, Integrations::Thor)
27
+ execution do
28
+ ::Thor.send(:include, Thor)
29
+ end
29
30
  end
30
31
  end
31
32
  end
@@ -1,5 +1,8 @@
1
+ require 'honeybadger/plugin'
2
+ require 'honeybadger/agent'
3
+
1
4
  module Honeybadger
2
- module Integrations
5
+ module Plugins
3
6
  module Unicorn
4
7
  module AfterForkExtension
5
8
  def self.included(base)
@@ -9,18 +12,16 @@ module Honeybadger
9
12
 
10
13
  def init_worker_process_with_honeybadger(*args, &block)
11
14
  init_worker_process_without_honeybadger(*args, &block).tap do
12
- Honeybadger::Monitor.worker.fork
15
+ Honeybadger::Agent.fork
13
16
  end
14
17
  end
15
18
  end
16
- end
17
- end
18
19
 
19
- Dependency.register do
20
- requirement { defined?(::Honeybadger::Monitor) }
21
- requirement { defined?(::Unicorn::HttpServer) }
20
+ Plugin.register do
21
+ requirement { defined?(::Unicorn::HttpServer) }
22
22
 
23
- injection { Honeybadger.write_verbose_log('Installing Unicorn integration') }
24
- injection { ::Unicorn::HttpServer.send(:include, Integrations::Unicorn::AfterForkExtension) }
23
+ execution { ::Unicorn::HttpServer.send(:include, AfterForkExtension) }
24
+ end
25
+ end
25
26
  end
26
27
  end
@@ -1,12 +1,15 @@
1
+ require 'rack'
2
+ require 'honeybadger'
3
+ require 'forwardable'
4
+
1
5
  module Honeybadger
2
6
  module Rack
3
- # Middleware for Rack applications. Any errors raised by the upstream
7
+ # Public: Middleware for Rack applications. Any errors raised by the upstream
4
8
  # application will be delivered to Honeybadger and re-raised.
5
9
  #
6
- # Synopsis:
10
+ # Examples:
7
11
  #
8
- # require 'rack'
9
- # require 'honeybadger'
12
+ # require 'honeybadger/rack/error_notifier'
10
13
  #
11
14
  # Honeybadger.configure do |config|
12
15
  # config.api_key = 'my_api_key'
@@ -21,39 +24,53 @@ module Honeybadger
21
24
  #
22
25
  # Use a standard Honeybadger.configure call to configure your api key.
23
26
  class ErrorNotifier
24
- def initialize(app)
27
+ extend Forwardable
28
+
29
+ def initialize(app, config)
25
30
  @app = app
26
- Honeybadger.configuration.framework = "Rack: #{::Rack.release}"
31
+ @config = config
32
+ end
33
+
34
+ def call(env)
35
+ config.with_request(::Rack::Request.new(env)) do
36
+ begin
37
+ env['honeybadger.config'] = config
38
+ response = @app.call(env)
39
+ rescue Exception => raised
40
+ env['honeybadger.error_id'] = notify_honeybadger(raised, env)
41
+ raise
42
+ end
43
+
44
+ framework_exception = framework_exception(env)
45
+ if framework_exception
46
+ env['honeybadger.error_id'] = notify_honeybadger(framework_exception, env)
47
+ end
48
+
49
+ response
50
+ end
51
+ ensure
52
+ Honeybadger.context.clear!
27
53
  end
28
54
 
55
+ private
56
+
57
+ attr_reader :config
58
+ def_delegator :@config, :logger
59
+
29
60
  def ignored_user_agent?(env)
30
- true if Honeybadger.
31
- configuration.
32
- ignore_user_agent.
61
+ true if config[:'exceptions.ignored_user_agents'].
33
62
  flatten.
34
63
  any? { |ua| ua === env['HTTP_USER_AGENT'] }
35
64
  end
36
65
 
37
- def notify_honeybadger(exception,env)
38
- Honeybadger.notify_or_ignore(exception, :rack_env => env) unless ignored_user_agent?(env)
66
+ def notify_honeybadger(exception, env)
67
+ return if ignored_user_agent?(env)
68
+ Honeybadger.notify_or_ignore(exception)
39
69
  end
40
70
 
41
- def call(env)
42
- begin
43
- response = @app.call(env)
44
- rescue Exception => raised
45
- env['honeybadger.error_id'] = notify_honeybadger(raised, env)
46
- raise
47
- end
48
-
49
- framework_exception = env['rack.exception'] || env['sinatra.error']
50
- if framework_exception
51
- env['honeybadger.error_id'] = notify_honeybadger(framework_exception, env)
52
- end
53
-
54
- response
55
- ensure
56
- Honeybadger.context.clear!
71
+ def framework_exception(env)
72
+ env['action_dispatch.exception'] || env['rack.exception'] ||
73
+ env['sinatra.error'] || env['honeybadger.exception']
57
74
  end
58
75
  end
59
76
  end