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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f504706a430b22213b3c9981b53606bfffb5a3e
4
- data.tar.gz: 19a64023b5f8f8e57742b9cca18957fbac3fb341
3
+ metadata.gz: 7da3276ec8bbc96881dc0edf11dfa62dfb0081dc
4
+ data.tar.gz: dd2d483879772690a1049a6de31bcaf37058d09a
5
5
  SHA512:
6
- metadata.gz: 3515fc0c08d2ead1a57ed88426c770e3fb53a441b8e8345c5f6df99fdbcac1aeb85d4c1c4179ea379d6887eda35f59913afd070cca5bfd2abe9a66dbbc015d4a
7
- data.tar.gz: 56102dc006a238c7d1c404146356f1e1180c7e909125b8db644243a7d2a1dbf5af5d98c1cd346c25a1d02e48b1e8792a54d67b70e60429976665a7c50db1a9ef
6
+ metadata.gz: afa97bb207635301b1106641a54408b1024858449a275b31ea7eec3fc4c404f69b4d65b3cffac35a70ab04866fa4f7fe36e277f8233fc6bba3743c90473cafdc
7
+ data.tar.gz: 0b46525e824d08b42af3415a0c687eeed306a788a229c6dcd069e72432716512093b8a70d0e4fba5044cdf1e85d521f5c6d98b8da732daa8abbd071816c76f31
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Honeybadger Industries LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,29 +1,52 @@
1
- # Honeybadger
1
+ # Honeybadger for Ruby
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/honeybadger-io/honeybadger-ruby/badges/gpa.svg)](https://codeclimate.com/github/honeybadger-io/honeybadger-ruby)
3
4
  [![Build Status](https://secure.travis-ci.org/honeybadger-io/honeybadger-ruby.png?branch=master)](http://travis-ci.org/honeybadger-io/honeybadger-ruby)
4
5
  [![Gem Version](https://badge.fury.io/rb/honeybadger.png)](http://badge.fury.io/rb/honeybadger)
5
6
 
6
7
  This is the notifier gem for integrating apps with the :zap: [Honeybadger Exception Notifier for Ruby and Rails](http://honeybadger.io).
7
8
 
8
- When an uncaught exception occurs, Honeybadger will POST the relevant data
9
- to the Honeybadger server specified in your environment.
9
+ When an uncaught exception occurs, Honeybadger will POST the relevant data to the Honeybadger server specified in your environment.
10
10
 
11
11
  ## Supported Ruby versions
12
12
 
13
- #### IMPORTANT: As of version 1.16.0, Ruby 1.8.7 and 1.9.2 are unsupported. Please ensure you are running Ruby 1.9.3 or greater before upgrading.
13
+ Honeybadger officially supports the following Ruby versions and implementations:
14
14
 
15
- Honeybadger supports Ruby 1.9.3 through 2.2.
15
+ | Ruby | Version |
16
+ | ------------- | ------------------|
17
+ | MRI | >= 1.9.3 |
18
+ | JRuby | >= 1.7 (1.9 mode) |
19
+ | Rubinius | >= 2.0 |
16
20
 
17
- ## Supported Rails versions
21
+ ## Supported frameworks
18
22
 
19
- Honeybadger supports Rails 2.3 through Rails 4.2 (latest releases).
23
+ The following frameworks are supported:
24
+
25
+ | Framework | Version | Native? |
26
+ | ------------- | ------------- |------------|
27
+ | Rails | >= 3.0 | yes |
28
+ | Sinatra | >= 1.2.1 | yes |
29
+ | Rack | >= 1.0 | middleware |
30
+
31
+ Rails and Sinatra are supported natively (install/configure the gem and you're done). For vanilla Rack apps, we provide a collection of middleware that must be installed manually.
32
+
33
+ Integrating with other libraries/frameworks is simple! [See the documentation](http://rubydoc.info/gems/honeybadger/) to learn about our public API, and see [Contributing](#contributing) to suggest a patch.
20
34
 
21
35
  ## Documentation
22
36
 
23
- [View the Documentation](http://docs.honeybadger.io/article/50-honeybadger-gem-documentation)
37
+ * [Basic usage](http://rubydoc.info/gems/honeybadger/)
38
+ * [Full documentation](http://docs.honeybadger.io/article/50-honeybadger-gem-documentation)
39
+
40
+ ## Changelog
41
+
42
+ See https://github.com/honeybadger-io/honeybadger-ruby/releases
24
43
 
25
44
  ## Contributing
26
45
 
46
+ If you're adding a new feature, please [submit an issue](https://github.com/honeybadger-io/honeybadger-ruby/issues/new) as a preliminary step; that way you can be (moderately) sure that your pull request will be accepted.
47
+
48
+ ### To contribute your code:
49
+
27
50
  1. Fork it.
28
51
  2. Create a topic branch `git checkout -b my_branch`
29
52
  3. Commit your changes `git commit -am "Boom"`
@@ -32,15 +55,13 @@ Honeybadger supports Rails 2.3 through Rails 4.2 (latest releases).
32
55
 
33
56
  ### Running the tests
34
57
 
35
- We're using the
36
- [appraisal](https://github.com/thoughtbot/appraisal) gem to run our test
37
- suite against multiple versions of Rails. To run the Cucumber features,
38
- use `rake appraisal cucumber`. Type `rake -T` for a complete list of
39
- available tasks.
58
+ We're using the [Appraisal](https://github.com/thoughtbot/appraisal) gem to run
59
+ our [RSpec](https://www.relishapp.com/rspec/) test suite against multiple
60
+ versions of [Rails](http://rubyonrails.org/).
40
61
 
41
- The RSpec test suite can be run with `rake`, or
42
- `rake appraisal:rails2.3` to include Rails-specific specs.
62
+ * The unit test suite can be run with `rake` (aliased to `rake spec:unit`).
63
+ * The integration test suite can be run with `rake spec:features`.
43
64
 
44
65
  ### License
45
66
 
46
- The Honeybadger gem is MIT licensed. See the [MIT-LICENSE](https://raw.github.com/honeybadger-io/honeybadger-ruby/master/MIT-LICENSE) file in this repository for details.
67
+ The Honeybadger gem is MIT licensed. See the [LICENSE](https://raw.github.com/honeybadger-io/honeybadger-ruby/master/LICENSE) file in this repository for details.
data/bin/honeybadger ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/honeybadger/cli.rb', __FILE__)
4
+
5
+ Honeybadger::CLI.start(ARGV)
data/lib/honeybadger.rb CHANGED
@@ -1,204 +1,180 @@
1
- require 'net/http'
2
- require 'net/https'
3
- require 'json'
4
- require 'digest'
5
- require 'logger'
6
-
7
- require 'honeybadger/dependency'
8
- require 'honeybadger/configuration'
9
- require 'honeybadger/backtrace'
10
- require 'honeybadger/notice'
11
- require 'honeybadger/rack'
12
- require 'honeybadger/sender'
13
- require 'honeybadger/stats'
14
- require 'honeybadger/user_informer'
15
- require 'honeybadger/user_feedback'
16
- require 'honeybadger/integrations'
17
-
18
- require 'honeybadger/railtie' if defined?(Rails::Railtie)
19
- require 'honeybadger/monitor'
1
+ require 'forwardable'
2
+ require 'honeybadger/const'
20
3
 
21
4
  module Honeybadger
22
- VERSION = '1.16.7'.freeze
23
- LOG_PREFIX = "** [Honeybadger] ".freeze
24
-
25
- HEADERS = {
26
- 'Content-type' => 'application/json',
27
- 'Content-Encoding' => 'deflate',
28
- 'Accept' => 'text/json, application/json',
29
- 'User-Agent' => "HB-Ruby #{VERSION}; #{RUBY_VERSION}; #{RUBY_PLATFORM}"
30
- }.freeze
31
-
32
- class << self
33
- # The sender object is responsible for delivering formatted data to the
34
- # Honeybadger server. Must respond to #send_to_honeybadger. See Honeybadger::Sender.
35
- attr_accessor :sender
36
-
37
- # A Honeybadger configuration object. Must act like a hash and return sensible
38
- # values for all Honeybadger configuration options. See Honeybadger::Configuration.
39
- attr_writer :configuration
40
-
41
- # Tell the log that the Notifier is good to go
42
- def report_ready
43
- write_verbose_log("Notifier #{VERSION} ready to catch errors", :info)
44
- end
45
-
46
- # Prints out the environment info to the log for debugging help
47
- def report_environment_info
48
- write_verbose_log("Environment Info: #{environment_info}")
49
- end
50
-
51
- # Prints out the response body from Honeybadger for debugging help
52
- def report_response_body(response)
53
- write_verbose_log("Response from Honeybadger: \n#{response}")
54
- end
55
-
56
- # Returns the Ruby version, Rails version, and current Rails environment
57
- def environment_info
58
- info = "[Ruby: #{RUBY_VERSION}]"
59
- info << " [#{configuration.framework}]" if configuration.framework
60
- info << " [Env: #{configuration.environment_name}]" if configuration.environment_name
61
- end
62
-
63
- # Writes out the given message to the #logger
64
- def write_verbose_log(message, level = Honeybadger.configuration.debug ? :info : :debug)
65
- logger.send(level, LOG_PREFIX + message) if logger
66
- end
67
-
68
- # Look for the Rails logger currently defined
69
- def logger
70
- self.configuration.logger
71
- end
72
-
73
- # Public: Call this method to modify defaults in your initializers.
74
- #
75
- # Examples:
76
- #
77
- # Honeybadger.configure do |config|
78
- # config.api_key = '1234567890abcdef'
79
- # config.secure = false
80
- # end
81
- #
82
- # Yields Honeybadger configuration
83
- def configure(silent = false)
84
- yield(configuration)
85
- self.sender = Sender.new(configuration)
86
- report_ready unless silent
87
- self.sender
88
- end
89
-
90
- # Public: The configuration object.
91
- # See Honeybadger.configure
92
- #
93
- # Returns Honeybadger configuration
94
- def configuration
95
- @configuration ||= Configuration.new
96
- end
97
-
98
- # Internal: Contacts the Honeybadger service and configures features
99
- #
100
- # configuration - the Configuration object to use
101
- #
102
- # Returns Hash features on success, NilClass on failure
103
- def ping(configuration)
104
- if configuration.public?
105
- if result = sender.ping({ :version => Honeybadger::VERSION, :framework => configuration.framework, :environment => configuration.environment_name, :hostname => configuration.hostname })
106
- if features = result['features']
107
- configuration.features = features
108
- configuration.metrics = false unless features['metrics']
109
- configuration.traces = false unless features['traces']
110
- features
111
- end
112
- end
113
- end
114
- end
115
-
116
- # Public: Sends an exception manually using this method, even when you are not in a controller.
117
- #
118
- # exception - The exception you want to notify Honeybadger about.
119
- # options - Data that will be sent to Honeybadger.
120
- # :api_key - The API key for this project. The API key is a unique identifier
121
- # that Honeybadger uses for identification.
122
- # :error_message - The error returned by the exception (or the message you want to log).
123
- # :backtrace - A backtrace, usually obtained with +caller+.
124
- # :rack_env - The Rack environment.
125
- # :session - The contents of the user's session.
126
- # :environment_name - The application environment name.
127
- # :context - Custom hash to send
128
- #
129
- # Returns exception ID from Honeybadger on success, false on failure
130
- def notify(exception, options = {})
131
- send_notice(build_notice_for(exception, options))
132
- end
133
-
134
- # Public: Sends the notice unless it is one of the default ignored exceptions
135
- # see Honeybadger.notify
136
- def notify_or_ignore(exception, opts = {})
137
- notice = build_notice_for(exception, opts)
138
- send_notice(notice) unless notice.ignore?
139
- end
140
-
141
- def build_lookup_hash_for(exception, options = {})
142
- notice = build_notice_for(exception, options)
143
-
144
- result = {}
145
- result[:action] = notice.action rescue nil
146
- result[:component] = notice.component rescue nil
147
- result[:error_class] = notice.error_class if notice.error_class
148
- result[:environment_name] = 'production'
149
-
150
- unless notice.backtrace.lines.empty?
151
- result[:file] = notice.backtrace.lines[0].file
152
- result[:line_number] = notice.backtrace.lines[0].number
153
- end
154
-
155
- result
156
- end
157
-
158
- def context(hash = nil)
159
- unless hash.nil?
160
- Thread.current[:honeybadger_context] ||= {}
161
- Thread.current[:honeybadger_context].merge!(hash)
162
- end
5
+ include Forwardable
6
+
7
+ extend self
8
+
9
+ # Public: Starts the Honeybadger service.
10
+ #
11
+ # opts - The Hash options used to initialize Honeybadger. Accepts config
12
+ # keys in addition to the listed options. Order of precedence for
13
+ # config is: 1) ENV, 2) config on disk, 3) opts. (default: {})
14
+ # :logger - An alternate Logger to use. (optional)
15
+ #
16
+ # Examples:
17
+ #
18
+ # ENV['HONEYBADGER_API_KEY'] # => 'asdf'
19
+ #
20
+ # Honeybadger.start # => true
21
+ #
22
+ # Honeybadger.start({
23
+ # :root => ::Rails.root,
24
+ # :'config.path' => 'config/',
25
+ # :logger => Honeybadger::Logging::FormattedLogger.new(::Rails.logger)
26
+ # }) # => true
27
+ #
28
+ # Returns true if started, otherwise false.
29
+ def start(config = {})
30
+ Agent.start(config)
31
+ end
163
32
 
164
- self
165
- end
33
+ # Public: Stops the Honeybadger service.
34
+ #
35
+ # Examples:
36
+ #
37
+ # Honeybadger.stop # => nil
38
+ #
39
+ # Returns nothing
40
+ def stop
41
+ Agent.stop
42
+ end
166
43
 
167
- def clear!
168
- Thread.current[:honeybadger_context] = nil
169
- end
44
+ # Public: Send an exception to Honeybadger.
45
+ #
46
+ # exception_or_opts - An Exception object, or a Hash of options which is used
47
+ # to build the notice.
48
+ # opts - The options Hash when the first argument is an
49
+ # Exception. (default: {}):
50
+ # :error_class - The String class name of the error.
51
+ # :error_message - The String error message.
52
+ #
53
+ # Examples:
54
+ #
55
+ # # With an exception:
56
+ # begin
57
+ # fail 'oops'
58
+ # rescue => exception
59
+ # Honeybadger.notify(exception, context: {
60
+ # my_data: 'value'
61
+ # }) # => '0dfb92ae-9b01-42e9-9c13-31205b70744a'
62
+ # end
63
+ #
64
+ # # Custom notification:
65
+ # Honeybadger.notify({
66
+ # error_class: 'MyClass',
67
+ # error_message: 'Something went wrong.',
68
+ # context: {my_data: 'value'}
69
+ # }) # => '06221c5a-b471-41e5-baeb-de247da45a56'
70
+ #
71
+ # Returns a String UUID reference to the notice within Honeybadger.
72
+ def notify(exception_or_opts, opts = {})
73
+ opts.merge!(exception: exception_or_opts) if exception_or_opts.is_a?(Exception)
74
+ opts.merge!(exception_or_opts.to_hash) if exception_or_opts.respond_to?(:to_hash)
75
+ Agent.instance ? Agent.instance.notice(opts) : false
76
+ end
170
77
 
171
- private
78
+ # Deprecated: Legacy support.
79
+ alias_method :notify_or_ignore, :notify
80
+
81
+ # Public: Callback to ignore exceptions.
82
+ #
83
+ # See public API documentation for Honeybadger::Notice for available attributes.
84
+ #
85
+ # block - A block returning TrueClass true (to ignore) or FalseClass false
86
+ # (to send).
87
+ #
88
+ # Examples:
89
+ #
90
+ # # Ignoring based on error message:
91
+ # Honeybadger.exception_filter do |notice|
92
+ # notice[:error_message] =~ /sensitive data/
93
+ # end
94
+ #
95
+ # # Ignore an entire class of exceptions:
96
+ # Honeybadger.exception_filter do |notice|
97
+ # notice[:exception].class < MyError
98
+ # end
99
+ #
100
+ # Returns nothing.
101
+ def exception_filter(&block)
102
+ Agent.exception_filter(&block)
103
+ end
172
104
 
173
- def send_notice(notice)
174
- return false unless sender
105
+ # Public: Callback to add a custom grouping strategy for exceptions. The
106
+ # return value is hashed and sent to Honeybadger. Errors with the same
107
+ # fingerprint will be grouped.
108
+ #
109
+ # See public API documentation for Honeybadger::Notice for available attributes.
110
+ #
111
+ # block - A block returning any Object responding to #to_s.
112
+ #
113
+ # Examples:
114
+ #
115
+ # Honeybadger.exception_fingerprint do |notice|
116
+ # [notice[:error_class], notice[:component], notice[:backtrace].to_s].join(':')
117
+ # end
118
+ #
119
+ # Returns nothing.
120
+ def exception_fingerprint(&block)
121
+ Agent.exception_fingerprint(&block)
122
+ end
175
123
 
176
- if configuration.public?
177
- if configuration.async?
178
- configuration.async.call(notice)
179
- else
180
- Honeybadger.sender.send_to_honeybadger(notice)
181
- end
182
- end
183
- end
124
+ # Public: Callback to filter backtrace lines. One use for this is to make
125
+ # additional [PROJECT_ROOT] or [GEM_ROOT] substitutions, which are used by
126
+ # Honeybadger when grouping errors and displaying application traces.
127
+ #
128
+ # block - A block which can be used to modify the Backtrace lines sent to
129
+ # Honeybadger. The block expects one argument (line) which is the String line
130
+ # from the Backtrace, and must return the String new line.
131
+ #
132
+ # Examples:
133
+ #
134
+ # Honeybadger.backtrace_filter do |line|
135
+ # line.gsub(/^\/my\/unknown\/bundle\/path/, "[GEM_ROOT]")
136
+ # end
137
+ #
138
+ # Returns nothing.
139
+ def backtrace_filter(&block)
140
+ Agent.backtrace_filter(&block)
141
+ end
184
142
 
185
- def build_notice_for(exception, opts = {})
186
- exception = unwrap_exception(exception)
187
- opts = opts.merge(:exception => exception) if exception.is_a?(Exception)
188
- opts = opts.merge(exception.to_hash) if exception.respond_to?(:to_hash)
189
- Notice.new(configuration.merge(opts))
190
- end
143
+ # Public: Save global context for the current request.
144
+ #
145
+ # hash - A Hash of data which will be sent to Honeybadger when an error
146
+ # occurs. (default: nil)
147
+ #
148
+ # Examples:
149
+ #
150
+ # Honeybadger.context({my_data: 'my value'})
151
+ #
152
+ # # Inside a Rails controller:
153
+ # before_action do
154
+ # Honeybadger.context({user_id: current_user.id})
155
+ # end
156
+ #
157
+ # # Clearing global context:
158
+ # Honeybadger.context.clear!
159
+ #
160
+ # Returns self so that method calls can be chained.
161
+ def context(hash = nil)
162
+ unless hash.nil?
163
+ Thread.current[:__honeybadger_context] ||= {}
164
+ Thread.current[:__honeybadger_context].merge!(hash)
165
+ end
166
+
167
+ self
168
+ end
191
169
 
192
- def unwrap_exception(exception)
193
- return exception unless configuration.unwrap_exceptions
194
- exception.respond_to?(:original_exception) && exception.original_exception ||
195
- exception.respond_to?(:continued_exception) && exception.continued_exception ||
196
- exception.respond_to?(:cause) && exception.cause ||
197
- exception
198
- end
170
+ # Internal: Clears the global context
171
+ def clear!
172
+ Thread.current[:__honeybadger_context] = nil
199
173
  end
200
174
  end
201
175
 
202
- unless defined?(Rails)
203
- Honeybadger::Dependency.inject!
176
+ if defined?(::Rails::Railtie)
177
+ require 'honeybadger/init/rails'
178
+ elsif defined?(Sinatra::Base)
179
+ require 'honeybadger/init/sinatra'
204
180
  end