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
@@ -1,94 +0,0 @@
1
- require 'honeybadger'
2
- require File.join(File.dirname(__FILE__), 'shared_tasks')
3
-
4
- namespace :honeybadger do
5
- desc "Verify your gem installation by sending a test exception to the honeybadger service"
6
- task :test => :environment do
7
- Rails.logger = if defined?(ActiveSupport::TaggedLogging)
8
- ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
9
- else
10
- Logger.new(STDOUT)
11
- end
12
- Rails.logger.level = Logger::INFO
13
-
14
- Honeybadger.configure(true) do |config|
15
- config.logger = Rails.logger
16
- config.debug = true
17
- config.development_environments = []
18
- config.rescue_rake_exceptions = false
19
- end
20
-
21
- # Suppress error logging in Rails' exception handling middleware. Rails 3.0
22
- # uses ActionDispatch::ShowExceptions to rescue/show exceptions, but does
23
- # not log anything but application trace. Rails 3.2 now falls back to
24
- # logging the framework trace (moved to ActionDispatch::DebugExceptions),
25
- # which caused cluttered output while running the test task.
26
- class ActionDispatch::DebugExceptions ; def logger(*args) ; @logger ||= Logger.new('/dev/null') ; end ; end
27
- class ActionDispatch::ShowExceptions ; def logger(*args) ; @logger ||= Logger.new('/dev/null') ; end ; end
28
-
29
- # Detect and disable the better_errors gem
30
- if defined? BetterErrors::Middleware
31
- puts 'Better Errors detected: temporarily disabling middleware.'
32
- class BetterErrors::Middleware ; def call(env) @app.call(env); end ; end
33
- end
34
-
35
- begin
36
- require './app/controllers/application_controller'
37
- rescue LoadError
38
- nil
39
- end
40
-
41
- class HoneybadgerTestingException < RuntimeError; end
42
-
43
- unless Honeybadger.configuration.api_key
44
- puts "Honeybadger needs an API key configured! Check the README to see how to add it."
45
- exit
46
- end
47
-
48
- if Honeybadger.configuration.async?
49
- puts "Temporarily disabling asynchronous delivery"
50
- Honeybadger.configuration.async = nil
51
- end
52
-
53
- puts "Configuration:"
54
- Honeybadger.configuration.to_hash.each do |key, value|
55
- puts sprintf("%25s: %s", key.to_s, value.inspect.slice(0, 55))
56
- end
57
-
58
- unless defined?(ApplicationController)
59
- puts "No ApplicationController found"
60
- exit
61
- end
62
-
63
- puts 'Setting up the Controller.'
64
- class ApplicationController
65
- # This is to bypass any filters that may prevent access to the action.
66
- prepend_before_filter :test_honeybadger
67
- def test_honeybadger
68
- puts "Raising '#{exception_class.name}' to simulate application failure."
69
- raise exception_class.new, 'Testing honeybadger via "rake honeybadger:test". If you can see this, it works.'
70
- end
71
-
72
- # Ensure we actually have an action to go to.
73
- def verify; end
74
-
75
- def exception_class
76
- exception_name = ENV['EXCEPTION'] || "HoneybadgerTestingException"
77
- Object.const_get(exception_name)
78
- rescue
79
- Object.const_set(exception_name, Class.new(Exception))
80
- end
81
- end
82
-
83
- Rails.application.routes.draw do
84
- match 'verify' => 'application#verify', :as => 'verify', :via => :get
85
- end
86
-
87
- puts 'Processing request.'
88
-
89
- ssl = defined?(Rails.configuration.force_ssl) && Rails.configuration.force_ssl
90
- env = Rack::MockRequest.env_for("http#{ ssl ? 's' : nil }://www.example.com/verify", 'REMOTE_ADDR' => '127.0.0.1')
91
-
92
- Rails.application.call(env)
93
- end
94
- end
@@ -1,52 +0,0 @@
1
- require 'honeybadger'
2
- require 'rails'
3
-
4
- module Honeybadger
5
- class Railtie < Rails::Railtie
6
- rake_tasks do
7
- require 'honeybadger/rake_handler'
8
- require "honeybadger/rails3_tasks"
9
- end
10
-
11
- initializer "honeybadger.use_rack_middleware" do |app|
12
- app.config.middleware.insert 0, "Honeybadger::Rack::UserInformer"
13
- app.config.middleware.insert_after "Honeybadger::Rack::UserInformer","Honeybadger::Rack::UserFeedback"
14
- app.config.middleware.insert_after "Honeybadger::Rack::UserFeedback","Honeybadger::Rack::ErrorNotifier"
15
- end
16
-
17
- config.after_initialize do
18
- Honeybadger.configure(true) do |config|
19
- config.logger ||= ::Rails.logger
20
- config.environment_name ||= ::Rails.env
21
- config.project_root ||= ::Rails.root
22
- config.framework = "Rails: #{::Rails::VERSION::STRING}"
23
- end
24
-
25
- ActiveSupport.on_load(:action_controller) do
26
- # Lazily load action_controller methods
27
- #
28
- require 'honeybadger/rails/controller_methods'
29
-
30
- include Honeybadger::Rails::ControllerMethods
31
- end
32
-
33
- if defined?(::ActionDispatch::DebugExceptions)
34
- # We should catch the exceptions in ActionDispatch::DebugExceptions in Rails 3.2.x.
35
- #
36
- require 'honeybadger/rails/middleware/exceptions_catcher'
37
- ::ActionDispatch::DebugExceptions.send(:include,Honeybadger::Rails::Middleware::ExceptionsCatcher)
38
- elsif defined?(::ActionDispatch::ShowExceptions)
39
- # ActionDispatch::DebugExceptions is not defined in Rails 3.0.x and 3.1.x so
40
- # catch the exceptions in ShowExceptions.
41
- #
42
- require 'honeybadger/rails/middleware/exceptions_catcher'
43
- ::ActionDispatch::ShowExceptions.send(:include,Honeybadger::Rails::Middleware::ExceptionsCatcher)
44
- end
45
-
46
- Honeybadger.ping(Honeybadger.configuration)
47
-
48
- # Inject last, in case we're depending on configuration from ping.
49
- Honeybadger::Dependency.inject!
50
- end
51
- end
52
- end
@@ -1,66 +0,0 @@
1
- # Patch Rake::Application to handle errors with Honeybadger
2
- module Honeybadger::RakeHandler
3
- def self.included(klass)
4
- klass.class_eval do
5
- include Rake087Methods unless defined?(Rake::VERSION) && Rake::VERSION >= '0.9.0'
6
- alias_method :display_error_message_without_honeybadger, :display_error_message
7
- alias_method :display_error_message, :display_error_message_with_honeybadger
8
- end
9
- end
10
-
11
- def display_error_message_with_honeybadger(ex)
12
- if Honeybadger.sender && Honeybadger.configuration &&
13
- (Honeybadger.configuration.rescue_rake_exceptions ||
14
- (Honeybadger.configuration.rescue_rake_exceptions===nil && !self.tty_output?))
15
-
16
- Honeybadger.notify_or_ignore(ex, :component => reconstruct_command_line)
17
- Honeybadger.context.clear!
18
- end
19
-
20
- display_error_message_without_honeybadger(ex)
21
- end
22
-
23
- def reconstruct_command_line
24
- "rake #{ARGV.join( ' ' )}"
25
- end
26
-
27
- # This module brings Rake 0.8.7 error handling to 0.9.0 standards
28
- module Rake087Methods
29
- # Method taken from Rake 0.9.0 source
30
- #
31
- # Provide standard exception handling for the given block.
32
- def standard_exception_handling
33
- begin
34
- yield
35
- rescue SystemExit => ex
36
- # Exit silently with current status
37
- raise
38
- rescue OptionParser::InvalidOption => ex
39
- $stderr.puts ex.message
40
- exit(false)
41
- rescue Exception => ex
42
- # Exit with error message
43
- display_error_message(ex)
44
- exit(false)
45
- end
46
- end
47
-
48
- # Method extracted from Rake 0.8.7 source
49
- def display_error_message(ex)
50
- $stderr.puts "#{name} aborted!"
51
- $stderr.puts ex.message
52
- if options.trace
53
- $stderr.puts ex.backtrace.join("\n")
54
- else
55
- $stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
56
- $stderr.puts "(See full trace by running task with --trace)"
57
- end
58
- end
59
- end
60
- end
61
-
62
- Rake.application.instance_eval do
63
- class << self
64
- include Honeybadger::RakeHandler
65
- end
66
- end
@@ -1,185 +0,0 @@
1
- require 'zlib'
2
- require 'stringio'
3
-
4
- module Honeybadger
5
- class Sender
6
- NOTICES_URI = '/v1/notices/'.freeze
7
- HTTP_ERRORS = [Timeout::Error,
8
- Errno::EINVAL,
9
- Errno::ECONNRESET,
10
- EOFError,
11
- Net::HTTPBadResponse,
12
- Net::HTTPHeaderSyntaxError,
13
- Net::ProtocolError,
14
- Errno::ECONNREFUSED].freeze
15
-
16
- def initialize(options = {})
17
- [ :api_key,
18
- :proxy_host,
19
- :proxy_port,
20
- :proxy_user,
21
- :proxy_pass,
22
- :protocol,
23
- :host,
24
- :port,
25
- :secure,
26
- :use_system_ssl_cert_chain,
27
- :http_open_timeout,
28
- :http_read_timeout
29
- ].each do |option|
30
- instance_variable_set("@#{option}", options[option])
31
- end
32
- end
33
-
34
- # Public: Sends the notice data off to Honeybadger for processing.
35
- #
36
- # notice - The notice to be sent (Notice, Hash or JSON string)
37
- #
38
- # Returns error id from successful response
39
- def send_to_honeybadger(notice)
40
- if !Honeybadger.configuration.features['notices']
41
- log(:error, "Can't send error report -- the gem has been deactivated by the remote service.\n\t" \
42
- "This is usually a result of an expired plan. Please check your payment info and restart your app.\n\t" \
43
- "If you continue to receive this message, contact support@honeybadger.io.")
44
- return nil
45
- end
46
-
47
- api_key = api_key_ok?(!notice.is_a?(String) && notice['api_key']) or return nil
48
-
49
- data = notice.is_a?(String) ? notice : notice.to_json
50
-
51
- response = send_request(url.path, data, {'X-API-Key' => api_key})
52
-
53
- if Net::HTTPSuccess === response
54
- log(Honeybadger.configuration.debug ? :info : :debug, "Success: #{response.class}", response, data)
55
- JSON.parse(response.body).fetch('id')
56
- else
57
- Honeybadger.configuration.features['notices'] = false if Net::HTTPForbidden === response
58
- log(:error, "Failure: #{response.class}", response, data)
59
- log_original_exception(notice)
60
- nil
61
- end
62
- rescue => e
63
- log(:error, "[Honeybadger::Sender#send_to_honeybadger] Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}")
64
- log_original_exception(notice)
65
- nil
66
- end
67
-
68
- def ping(data = {})
69
- return nil unless api_key_ok?
70
-
71
- data = data.to_json
72
- response = send_request('/v1/ping/', data)
73
-
74
- if Net::HTTPSuccess === response
75
- log(Honeybadger.configuration.debug ? :info : :debug, "Ping Success: #{response.class}", response)
76
- JSON.parse(response.body)
77
- else
78
- log(:error, "Ping Failure: #{response.class}", response, data)
79
- nil
80
- end
81
- rescue => e
82
- log(:error, "[Honeybadger::Sender#ping] Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}")
83
- nil
84
- end
85
-
86
- attr_reader :api_key,
87
- :proxy_host,
88
- :proxy_port,
89
- :proxy_user,
90
- :proxy_pass,
91
- :protocol,
92
- :host,
93
- :port,
94
- :secure,
95
- :use_system_ssl_cert_chain,
96
- :http_open_timeout,
97
- :http_read_timeout
98
-
99
- alias_method :secure?, :secure
100
- alias_method :use_system_ssl_cert_chain?, :use_system_ssl_cert_chain
101
-
102
- private
103
-
104
- def url
105
- URI.parse("#{protocol}://#{host}:#{port}").merge(NOTICES_URI)
106
- end
107
-
108
- def api_key_ok?(api_key = nil)
109
- api_key ||= self.api_key
110
- unless api_key =~ /\S/
111
- log(:error, "API key not found.")
112
- return nil
113
- end
114
-
115
- api_key
116
- end
117
-
118
- def log(level, message, response = nil, data = nil)
119
- # Log result:
120
- Honeybadger.write_verbose_log(message, level)
121
-
122
- # Log debug information:
123
- Honeybadger.report_environment_info
124
- Honeybadger.report_response_body(response.body) if response && response.body =~ /\S/
125
- Honeybadger.write_verbose_log("Notice: #{data}", :debug) if data && Honeybadger.configuration.debug
126
- end
127
-
128
- def send_request(path, data, headers = {})
129
- http_connection.post(path, compress(data), http_headers(headers))
130
- rescue *HTTP_ERRORS => e
131
- log(:error, "Unable to contact the Honeybadger server. HTTP Error=#{e}")
132
- nil
133
- end
134
-
135
- def http_connection
136
- setup_http_connection
137
- end
138
-
139
- def http_headers(headers=nil)
140
- {}.tap do |hash|
141
- hash.merge!(HEADERS)
142
- hash.merge!({'X-API-Key' => api_key})
143
- hash.merge!(headers) if headers
144
- end
145
- end
146
-
147
- def setup_http_connection
148
- http_class = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass)
149
- http = http_class.new(url.host, url.port)
150
-
151
- http.read_timeout = http_read_timeout
152
- http.open_timeout = http_open_timeout
153
-
154
- if secure?
155
- http.use_ssl = true
156
-
157
- http.ca_file = Honeybadger.configuration.ca_bundle_path
158
- http.verify_mode = OpenSSL::SSL::VERIFY_PEER
159
- else
160
- http.use_ssl = false
161
- end
162
-
163
- http
164
- rescue => e
165
- log(:error, "[Honeybadger::Sender#setup_http_connection] Failure initializing the HTTP connection.\nError: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}")
166
- raise e
167
- end
168
-
169
- def log_original_exception(notice)
170
- if Honeybadger.configuration.log_exception_on_send_failure
171
- if notice.respond_to?(:exception) && notice.respond_to?(:backtrace)
172
- message = "#{notice.error_message}\n#{notice.backtrace}"
173
- else
174
- message = "#{notice}"
175
- end
176
-
177
- Honeybadger.write_verbose_log("Original Exception: #{message}", :error)
178
- end
179
- end
180
-
181
- def compress(string, level = Zlib::DEFAULT_COMPRESSION)
182
- Zlib::Deflate.deflate(string, level)
183
- end
184
- end
185
- end
@@ -1,56 +0,0 @@
1
- namespace :honeybadger do
2
- desc "Notify Honeybadger of a new deploy."
3
- task :deploy do
4
- require 'honeybadger_tasks'
5
-
6
- if defined?(Rails.root)
7
- initializer_file = Rails.root.join('config', 'initializers','honeybadger.rb')
8
-
9
- if initializer_file.exist?
10
- load initializer_file
11
- else
12
- Rake::Task[:environment].invoke
13
- end
14
- end
15
-
16
- HoneybadgerTasks.deploy(:environment => ENV['TO'],
17
- :revision => ENV['REVISION'],
18
- :repository => ENV['REPO'],
19
- :local_username => ENV['USER'],
20
- :api_key => ENV['API_KEY'],
21
- :dry_run => ENV['DRY_RUN'])
22
- end
23
-
24
- task :deploy_with_environment => [:environment, :deploy]
25
-
26
- task :log_stdout do
27
- require 'logger'
28
- RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
29
- end
30
-
31
- namespace :heroku do
32
- desc "Install Heroku deploy notifications addon"
33
- task :add_deploy_notification => [:environment] do
34
- def heroku_var(var, app_name, default = nil)
35
- app = app_name ? "--app #{app_name}" : ''
36
- result = Bundler.with_clean_env { `heroku config:get #{var} #{app} 2> /dev/null`.strip }
37
- result.split.find(lambda { default }) {|x| x =~ /\S/ }
38
- end
39
-
40
- heroku_rails_env = heroku_var('RAILS_ENV', ENV['APP'], Honeybadger.configuration.environment_name)
41
- heroku_api_key = heroku_var('HONEYBADGER_API_KEY', ENV['APP'], Honeybadger.configuration.api_key)
42
-
43
- unless heroku_api_key =~ /\S/ && heroku_rails_env =~ /\S/
44
- puts "WARNING: We were unable to detect the configuration from your Heroku environment."
45
- puts "Your Heroku application environment may not be configured correctly."
46
- puts "Have you configured multiple Heroku apps? Try using APP=[app name]'" unless ENV['APP']
47
- exit
48
- end
49
-
50
- command = %Q(heroku addons:add deployhooks:http --url="https://api.honeybadger.io/v1/deploys?deploy[environment]=#{heroku_rails_env}&deploy[local_username]={{user}}&deploy[revision]={{head}}&api_key=#{heroku_api_key}"#{ENV['APP'] ? " --app #{ENV['APP']}" : ''})
51
-
52
- puts "\nRunning:\n#{command}\n"
53
- puts `#{command}`
54
- end
55
- end
56
- end