honeybadger 3.1.2 → 3.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/README.md +2 -750
- data/TROUBLESHOOTING.md +1 -135
- data/lib/honeybadger/agent.rb +48 -22
- data/lib/honeybadger/backend/base.rb +4 -4
- data/lib/honeybadger/backend/null.rb +11 -1
- data/lib/honeybadger/backend/test.rb +1 -1
- data/lib/honeybadger/backtrace.rb +1 -1
- data/lib/honeybadger/cli/main.rb +1 -1
- data/lib/honeybadger/cli/test.rb +9 -9
- data/lib/honeybadger/config.rb +6 -2
- data/lib/honeybadger/context_manager.rb +4 -1
- data/lib/honeybadger/conversions.rb +15 -0
- data/lib/honeybadger/logging.rb +2 -2
- data/lib/honeybadger/notice.rb +54 -39
- data/lib/honeybadger/plugins/sidekiq.rb +3 -2
- data/lib/honeybadger/rack/error_notifier.rb +1 -1
- data/lib/honeybadger/rack/user_feedback.rb +1 -1
- data/lib/honeybadger/singleton.rb +0 -2
- data/lib/honeybadger/util/sanitizer.rb +63 -17
- data/lib/honeybadger/util/stats.rb +2 -2
- data/lib/honeybadger/version.rb +1 -1
- data/lib/honeybadger/worker.rb +2 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c3dbe99d414f6c89625a0cad87334f0bc7a7176
|
4
|
+
data.tar.gz: 40431378fce7369c2e749fd389ab925609d38c18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e96e67c779f33c75ad30b2c0cd53081452b355bf499087cee3bf7cf2a2fc8d84e49b1dde0952a477e337476795247c6805578b80704fd7434959c7c67ddc5634
|
7
|
+
data.tar.gz: 7e9689d593714186c2382fa31265f646cd3ef6e4857651ac215648f7ef75a74312417997d899869cd2fdba6020a8cac4fcbd20439e5471e7619be9333828a910
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,34 @@ CHANGELOG](http://keepachangelog.com/) for how to update this file. This project
|
|
4
4
|
adheres to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
|
+
### Added
|
8
|
+
- The exception cause may now be set using an optional `:cause` option when
|
9
|
+
calling `Honeybadger.notify`. If not present, the exception's cause will be
|
10
|
+
used, or the global `$!` exception if available.
|
11
|
+
- Any object can now act as context using the `#to_honeybadger_context` method.
|
12
|
+
The method should have no arguments and return a `Hash` of context data.
|
13
|
+
Context from exceptions which define this method will automatically be
|
14
|
+
included in error reports.
|
15
|
+
- Final object representations in Honeybadger (normally the value of `#to_s`
|
16
|
+
for unknown types) can be changed by defining the `#to_honeybadger` method. If
|
17
|
+
the method is defined, the return value of that method will be sent to Honeybadger
|
18
|
+
instead of the `#to_s` value (for context values, local variables, etc.).
|
19
|
+
- `BasicObject`, which previously could not be serialized, is now serialized as
|
20
|
+
`"#<BasicObject>"`.
|
21
|
+
- Objects which explicitly alias `#to_s` to `#inspect` (such as `OpenStruct`) are
|
22
|
+
now sanitized. `'#<OpenStruct attribute="value">'` becomes `'#<OpenStruct>'`.
|
23
|
+
If you pass the value of `#inspect` (as a `String`) directly to Honeybadger (or
|
24
|
+
return it from `#to_honeybadger`), the value will not be sanitized.
|
25
|
+
- We're now using `String(object)` instead of `object.to_s` as the last resort
|
26
|
+
during sanitization.
|
27
|
+
- `'[RAISED]'` is returned when `object.to_honeybadger` or `String(object)` fails.
|
28
|
+
|
29
|
+
### Fixed
|
30
|
+
- We no longer use "/dev/null" as the default log device as it doesn't exist on
|
31
|
+
Windows.
|
32
|
+
- Logs when reporting errors in development mode now mention that the error wasn't
|
33
|
+
*actually* reported. :)
|
34
|
+
- Support new Sidekiq job params key.
|
7
35
|
|
8
36
|
## [3.1.2] - 2017-04-20
|
9
37
|
### Fixed
|
data/README.md
CHANGED
@@ -7,757 +7,9 @@ This is the notifier gem for integrating apps with the :zap: [Honeybadger Except
|
|
7
7
|
|
8
8
|
When an uncaught exception occurs, Honeybadger will POST the relevant data to the Honeybadger server specified in your environment.
|
9
9
|
|
10
|
-
##
|
10
|
+
## Documentation and Support
|
11
11
|
|
12
|
-
|
13
|
-
| ---- | ---- |
|
14
|
-
| MRI | >= 2.1.0 |
|
15
|
-
| JRuby | >= 9.1 |
|
16
|
-
|
17
|
-
## Supported web frameworks
|
18
|
-
|
19
|
-
| Framework | Version | Native? |
|
20
|
-
| ------------- | ------------- |------------|
|
21
|
-
| Rails | >= 3.2 | yes |
|
22
|
-
| Sinatra | >= 1.2.1 | yes |
|
23
|
-
| Rack | >= 1.0 | middleware |
|
24
|
-
|
25
|
-
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.
|
26
|
-
|
27
|
-
To use Rails 2.x, you'll need to use an earlier version of the Honeybadger gem. [Go to version 1.x of the gem docs](https://github.com/honeybadger-io/honeybadger-ruby/blob/1.16-stable/docs/index.md).
|
28
|
-
|
29
|
-
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.
|
30
|
-
|
31
|
-
## Supported job queues
|
32
|
-
|
33
|
-
| Library | Version | Native? |
|
34
|
-
| ------------- | ------------- | ------------ |
|
35
|
-
| Sidekiq | any | yes |
|
36
|
-
| Resque | any | yes |
|
37
|
-
| Delayed Job | any | yes |
|
38
|
-
| Sucker Punch | any | yes |
|
39
|
-
| Shoryuken | any | yes |
|
40
|
-
|
41
|
-
## Other integrations
|
42
|
-
|
43
|
-
| Library | Version | Native? | Description |
|
44
|
-
| ------------- | ------------- | ------------ | ----------- |
|
45
|
-
| Devise/Warden | any | yes | Exceptions are automatically associated with the current user. |
|
46
|
-
| Thor | any | yes | Exceptions in commands are automatically reported. |
|
47
|
-
|
48
|
-
You can integrate honeybadger into any Ruby script via the `Honeybadger.notify` method.
|
49
|
-
|
50
|
-
## Getting Started
|
51
|
-
|
52
|
-
Honeybadger works out of the box with all popular Ruby frameworks. Installation is just a matter of including the gem and setting your API key. In this section, we'll cover the basics. More advanced installations are covered later.
|
53
|
-
|
54
|
-
### 1. Install the gem
|
55
|
-
|
56
|
-
|
57
|
-
The first step is to add the honeybadger gem to your Gemfile:
|
58
|
-
|
59
|
-
```ruby
|
60
|
-
gem 'honeybadger'
|
61
|
-
```
|
62
|
-
|
63
|
-
Tell bundler to install:
|
64
|
-
|
65
|
-
```bash
|
66
|
-
$ bundle install
|
67
|
-
```
|
68
|
-
|
69
|
-
### 2. Set your API key
|
70
|
-
|
71
|
-
Next, you'll set the API key for this project.
|
72
|
-
|
73
|
-
```bash
|
74
|
-
$ bundle exec honeybadger install [YOUR API KEY HERE]
|
75
|
-
```
|
76
|
-
|
77
|
-
This will generate a `config/honeybadger.yml` file. If you don't like config files, you can place your API key in the `$HONEYBADGER_API_KEY` environment variable.
|
78
|
-
|
79
|
-
#### Heroku installation
|
80
|
-
|
81
|
-
If your app is deployed to heroku, you can configure Honeybadger on your dynos like so:
|
82
|
-
|
83
|
-
```bash
|
84
|
-
$ bundle exec honeybadger heroku install [YOUR API KEY HERE]
|
85
|
-
```
|
86
|
-
|
87
|
-
This will automatically add a `HONEYBADGER_API_KEY` environment variable to your
|
88
|
-
remote Heroku config and configure deploy notifications.
|
89
|
-
|
90
|
-
This step isn't necessary if you're using our [Heroku add-on](https://elements.heroku.com/addons/honeybadger).
|
91
|
-
|
92
|
-
### 3. Set up your code
|
93
|
-
|
94
|
-
#### Rails
|
95
|
-
|
96
|
-
You're done! Any rake tasks and job queues that load the Rails environment are also covered.
|
97
|
-
|
98
|
-
For more info, check out our screencast on getting up and running with Honeybadger and Rails:
|
99
|
-
|
100
|
-
[![Using the Honeybadger gem with Rails](https://embed-ssl.wistia.com/deliveries/e1e2133b8f1bec224c57f6677f6bdb11691b3822.jpg?image_play_button=true&image_play_button_color=7b796ae0&image_crop_resized=150x84)](https://honeybadger.wistia.com/medias/l3cmyucx8f)
|
101
|
-
|
102
|
-
#### Sinatra
|
103
|
-
|
104
|
-
All you need to do is to include the honeybadger gem:
|
105
|
-
|
106
|
-
```ruby
|
107
|
-
# Always require Sinatra first.
|
108
|
-
require 'sinatra'
|
109
|
-
# Then require honeybadger.
|
110
|
-
require 'honeybadger'
|
111
|
-
# Define your application code *after* Sinatra *and* honeybadger:
|
112
|
-
get '/' do
|
113
|
-
raise "Sinatra has left the building"
|
114
|
-
end
|
115
|
-
```
|
116
|
-
|
117
|
-
To see an example of a sinatra implementation, check out this video:
|
118
|
-
|
119
|
-
[![Using the Honeybadger gem with Sinatra](https://embed-ssl.wistia.com/deliveries/7c9b6e6831f2288874f24d10eec88116e9f378eb.jpg?image_play_button=true&image_play_button_color=7b796ae0&image_crop_resized=150x84)](https://honeybadger.wistia.com/medias/b2wr5n9fcv)
|
120
|
-
|
121
|
-
#### Rack
|
122
|
-
|
123
|
-
With rack, you have to do things manually, but it's still just a few lines of code:
|
124
|
-
|
125
|
-
```ruby
|
126
|
-
require 'rack'
|
127
|
-
|
128
|
-
# Load the gem
|
129
|
-
require 'honeybadger'
|
130
|
-
|
131
|
-
# Write your app
|
132
|
-
app = Rack::Builder.app do
|
133
|
-
run lambda { |env| raise "Rack down" }
|
134
|
-
end
|
135
|
-
|
136
|
-
# Use Honeybadger's rack middleware
|
137
|
-
use Honeybadger::Rack::ErrorNotifier
|
138
|
-
|
139
|
-
run app
|
140
|
-
```
|
141
|
-
|
142
|
-
#### Plain Ruby
|
143
|
-
|
144
|
-
To use Honeybadger without any of the automatic integrations, `require
|
145
|
-
honeybadger/ruby` instead of `require 'honeybadger'`:
|
146
|
-
|
147
|
-
```
|
148
|
-
require 'honeybadger/ruby'
|
149
|
-
|
150
|
-
begin
|
151
|
-
# Failing code
|
152
|
-
rescue => exception
|
153
|
-
Honeybadger.notify(exception)
|
154
|
-
end
|
155
|
-
```
|
156
|
-
|
157
|
-
All of the public API methods are still available, but none of the plugins,
|
158
|
-
framework integrations, or hooks are run. You will need to manually set up your
|
159
|
-
own middleware and hooks for error monitoring in whatever frameworks you use.
|
160
|
-
|
161
|
-
## Configuration
|
162
|
-
|
163
|
-
There are a few ways to configure the Honeybadger gem. You can use a YAML config file. You can use environment variables. You can use Ruby. Or you can use a combination of the three.
|
164
|
-
|
165
|
-
We put together a short video highligting a few of the most common configuration options:
|
166
|
-
|
167
|
-
[![Advanced Honeybadger Gem Usage](https://embed-ssl.wistia.com/deliveries/5fccf29d2b27d0f7ec62b5b39e2f5d9cd1f6f5b7.jpg?image_play_button=true&image_play_button_color=7b796ae0&image_crop_resized=150x84)](https://honeybadger.wistia.com/medias/vv9qq9x39d)
|
168
|
-
|
169
|
-
|
170
|
-
### YAML Configuration File
|
171
|
-
|
172
|
-
By default, Honeybadger looks for a `honeybadger.yml` configuration file in the root of your project, and then `config/honeybadger.yml` (in that order).
|
173
|
-
|
174
|
-
Here's what the simplest config file looks like:
|
175
|
-
|
176
|
-
```yaml
|
177
|
-
---
|
178
|
-
api_key: "my_api_key"
|
179
|
-
```
|
180
|
-
|
181
|
-
#### Nested Options
|
182
|
-
|
183
|
-
Some configuration options are written in YAML as nested hashes. For example, here's what the `logging.path` and `request.filter_keys` options look like in YAML:
|
184
|
-
|
185
|
-
```yaml
|
186
|
-
---
|
187
|
-
logging:
|
188
|
-
path: "/path/to/honeybadger.log"
|
189
|
-
request:
|
190
|
-
filter_keys:
|
191
|
-
- "credit_card"
|
192
|
-
```
|
193
|
-
|
194
|
-
#### Environments
|
195
|
-
|
196
|
-
Environment-specific options can be set by name-spacing the options beneath the environment name. For example:
|
197
|
-
|
198
|
-
```yaml
|
199
|
-
---
|
200
|
-
api_key: "my_api_key"
|
201
|
-
production:
|
202
|
-
logging:
|
203
|
-
path: "/path/to/honeybadger.log"
|
204
|
-
level: "WARN"
|
205
|
-
```
|
206
|
-
|
207
|
-
#### ERB and Regex
|
208
|
-
|
209
|
-
The configuration file is rendered using ERB. That means you can set configuration options programmatically. You can also include regular expressions. Here's what that looks like:
|
210
|
-
|
211
|
-
```yaml
|
212
|
-
---
|
213
|
-
api_key: "<%= MyApplication.config.api_key %>"
|
214
|
-
request:
|
215
|
-
filter_keys:
|
216
|
-
- !ruby/regexp '/credit_card/i'
|
217
|
-
```
|
218
|
-
|
219
|
-
### Configuring with Environment Variables (12-factor style)
|
220
|
-
|
221
|
-
All configuration options can also be read from environment variables (ENV). To do this, uppercase the option name, replace all non-alphanumeric characters with underscores, and prefix with `HONEYBADGER_`. For example, `logging.path` becomes `HONEYBADGER_LOGGING_PATH`:
|
222
|
-
|
223
|
-
```
|
224
|
-
export HONEYBADGER_LOGGING_PATH=/path/to/honeybadger.log
|
225
|
-
```
|
226
|
-
|
227
|
-
ENV options override other options read from framework or `honeybadger.yml` sources, so both can be used together.
|
228
|
-
|
229
|
-
### Configuration via Ruby (programmatic)
|
230
|
-
|
231
|
-
To configure Honeybadger from Ruby, use `Honeybadger.configure`:
|
232
|
-
|
233
|
-
```ruby
|
234
|
-
Honeybadger.configure do |config|
|
235
|
-
config.api_key = 'project api key'
|
236
|
-
config.exceptions.ignore += [CustomError]
|
237
|
-
end
|
238
|
-
```
|
239
|
-
|
240
|
-
## Configuration Options
|
241
|
-
|
242
|
-
You can use any of the options below in your config file, or in the environment.
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|Option | Type | Description |
|
247
|
-
|-------------------------------- | ------- | ----------- |
|
248
|
-
|`api_key` | String | The API key for your Honeybadger project.<br/>_Default: `nil`_|
|
249
|
-
|`env` | String | The environment the app is running in. In Rails this defaults to `Rails.env`.<br/>_Default: `nil`_|
|
250
|
-
|`report_data` | Boolean | Enable/disable reporting of data. Defaults to false for "test", "development", and "cucumber" environments. <br>_Default: `true`_|
|
251
|
-
|`root` | String | The project's absolute root path.<br/>_Default: `Dir.pwd`_|
|
252
|
-
|`revision` | String | The project's git revision.<br/>_Default: revision detected from git_|
|
253
|
-
|`hostname` | String | The hostname of the current box.<br/>_Default: `Socket.gethostname`_|
|
254
|
-
|`backend` | String | An alternate backend to use for reporting data.<br/>_Default: `nil`_|
|
255
|
-
|`debug` | Boolean | Enables verbose debug logging.<br/>_Default: `false`_|
|
256
|
-
|`send_data_at_exit` | Boolean | Finish sending enqueued exceptions before allowing program to exit.<br/>_Default: `true`_|
|
257
|
-
|`disabled` | Boolean | Prevents Honeybadger from starting entirely.<br/>_Default: `false`_|
|
258
|
-
| `config_path` | String | The path of the honeybadger config file. Can only be set via the `$HONEYBADGER_CONFIG_PATH` environment variable |
|
259
|
-
|`development_environments` | Array | Environments which will not report data by default (use report_data to enable/disable explicitly).<br/>_Default: `["development", "test", "cucumber"]`_|
|
260
|
-
|`plugins` | Array | An optional list of plugins to load. Default is to load all plugins.<br/>_Default: `[]`_|
|
261
|
-
|`skipped_plugins` | Array | An optional list of plugins to skip.<br/>_Default: `[]`_|
|
262
|
-
| | ||
|
263
|
-
|__LOGGING__ | ||
|
264
|
-
|`logging.path` | String | The path (absolute, or relative from config.root) to the log file. Defaults to the rails logger or STDOUT. To log to standard out, use 'STDOUT'.<br/>_Default: `nil`_|
|
265
|
-
|`logging.level` | String | The log level. Does nothing unless `logging.path` is also set.<br/>_Default: `INFO`_|
|
266
|
-
| | ||
|
267
|
-
|__HTTP CONNECTION__ | ||
|
268
|
-
|`connection.secure` | Boolean | Use SSL when sending data.<br/>_Default: `true`_|
|
269
|
-
|`connection.host` | String | The host to use when sending data.<br/>_Default: `api.honeybadger.io`_|
|
270
|
-
|`connection.port` | Integer | The port to use when sending data.<br/>_Default: `443`_|
|
271
|
-
|`connection.http_open_timeout` | Integer | The HTTP open timeout when connecting to the server.<br/>_Default: `2`_|
|
272
|
-
|`connection.http_read_timeout` | Integer | The HTTP read timeout when connecting to the server.<br/>_Default: `5`_|
|
273
|
-
|`connection.proxy_host` | String | The proxy host to use when sending data.<br/>_Default: `nil`_|
|
274
|
-
|`connection.proxy_port` | Integer | The proxy port to use when sending data.<br/>_Default: `nil`_|
|
275
|
-
|`connection.proxy_user` | String | The proxy user to use when sending data.<br/>_Default: `nil`_|
|
276
|
-
|`connection.proxy_pass` | String | The proxy password to use when sending data.<br/>_Default: `nil`_|
|
277
|
-
| | ||
|
278
|
-
|__REQUEST DATA FILTERING__ | ||
|
279
|
-
|`request.filter_keys` | Array | A list of keys to filter when sending request data. In Rails, this also includes existing params filters.<br/>*Default: `['password', 'password_confirmation']`*|
|
280
|
-
|`request.disable_session` | Boolean | Prevent session from being sent with request data.<br/>_Default: `false`_|
|
281
|
-
|`request.disable_params` | Boolean | Prevent params from being sent with request data.<br/>_Default: `false`_|
|
282
|
-
|`request.disable_environment` | Boolean | Prevent Rack environment from being sent with request data.<br/>_Default: `false`_|
|
283
|
-
|`request.disable_url` | Boolean | Prevent url from being sent with request data (Rack environment may still contain it in some cases).<br/>_Default: `false`_|
|
284
|
-
| | ||
|
285
|
-
|__USER INFORMER__ | ||
|
286
|
-
|`user_informer.enabled` | Boolean | Enable the UserInformer middleware. The user informer displays information about a Honeybadger error to your end-users when you display a 500 error page. This typically includes the error id which can be used to reference the error inside your Honeybadger account. [Learn More](http://docs.honeybadger.io/article/48-show-users-a-unique-id-when-they-encounter-an-error)<br/>_Default: `true`_|
|
287
|
-
|`user_informer.info` | String | Replacement string for HTML comment in templates.<br/>*Default: `'Honeybadger Error {{error_id}}'`*|
|
288
|
-
| | ||
|
289
|
-
|__USER FEEDBACK__ | ||
|
290
|
-
|`feedback.enabled` | Boolean | Enable the UserFeedback middleware. Feedback displays a comment form to your-end user when they encounter an error. When the user creates a comment, it is added to the error in Honeybadger, and a notification is sent. [Learn More](http://docs.honeybadger.io/article/166-how-to-implement-a-custom-feedback-form)<br/>_Default: `true`_|
|
291
|
-
| | ||
|
292
|
-
|__EXCEPTION REPORTING__ | ||
|
293
|
-
|`exceptions.ignore` | Array | A list of exception class names to ignore (appends to defaults).<br/>_Default: `['ActionController::RoutingError', 'AbstractController::ActionNotFound', 'ActionController::MethodNotAllowed', 'ActionController::UnknownHttpMethod', 'ActionController::NotImplemented', 'ActionController::UnknownFormat', 'ActionController::InvalidAuthenticityToken', 'ActionController::InvalidCrossOriginRequest', 'ActionDispatch::ParamsParser::ParseError', 'ActionController::BadRequest', 'ActionController::ParameterMissing', 'ActiveRecord::RecordNotFound', 'ActionController::UnknownAction', 'CGI::Session::CookieStore::TamperedWithCookie', 'Mongoid::Errors::DocumentNotFound', 'Sinatra::NotFound']`_|
|
294
|
-
|`exceptions.ignore_only` | Array | A list of exception class names to ignore (overrides defaults).<br/>_Default: `[]`_|
|
295
|
-
|`exceptions.` `ignored_user_agents` | Array | A list of user agents to ignore.<br/>_Default: `[]`_|
|
296
|
-
|`exceptions.rescue_rake` | Boolean | Enable rescuing exceptions in rake tasks.<br/>_Default: `true` when run in background; `false` when run in terminal._|
|
297
|
-
|`exceptions.notify_at_exit` | Boolean | Report unhandled exception when Ruby crashes (at\_exit).<br/>_Default: `true`._|
|
298
|
-
|`exceptions.source_radius` | Integer | The number of lines before and after the source when reporting snippets.<br/>_Default: `2`_|
|
299
|
-
|`exceptions.local_variables` | Boolean | Enable sending local variables. Requires the [binding_of_caller gem](https://rubygems.org/gems/binding_of_caller).<br/>_Default: `false`_|
|
300
|
-
|`exceptions.unwrap` | Boolean | Reports #original_exception or #cause one level up from rescued exception when available.<br/>_Default: `false`_|
|
301
|
-
| | ||
|
302
|
-
|__SIDEKIQ__ | ||
|
303
|
-
|`sidekiq.attempt_threshold` | Integer | The number of attempts before notifications will be sent.<br/>_Default: `0`_|
|
304
|
-
|`sidekiq.use_component` | Boolean | Automatically set the component to the class of the job. Helps with grouping.<br/>_Default: `true`_|
|
305
|
-
|__DELAYED JOB__ | ||
|
306
|
-
|`delayed_job.attempt_threshold` | Integer | The number of attempts before notifications will be sent.<br/>_Default: `0`_|
|
307
|
-
|__SHORYUKEN__ | ||
|
308
|
-
|`shoryuken.attempt_threshold` | Integer | The number of attempts before notifications will be sent.<br/>_Default: `0`_|
|
309
|
-
|__SINATRA__ | ||
|
310
|
-
|`sinatra.enabled` | Boolean | Enable Sinatra auto-initialization.<br/>_Default: `true`_|
|
311
|
-
|
312
|
-
## Public Methods
|
313
|
-
|
314
|
-
> What follows is a summary of the gem's most commonly-used public methods. For a more authoritative list, read the [full API documentation](http://www.rubydoc.info/gems/honeybadger/Honeybadger/Agent).
|
315
|
-
|
316
|
-
|
317
|
-
### `Honeybadger.context()`: Set metadata to be sent if an exception occurs
|
318
|
-
|
319
|
-
Sometimes, default exception data just isn't enough. If you have extra data that will help you in debugging, send it as part of an error's context. [View full method documentation](http://www.rubydoc.info/gems/honeybadger/Honeybadger%3Acontext)
|
320
|
-
|
321
|
-
Global context is stored in a thread local variable and automatically reported with any exception which occurs within the current thread's execution.
|
322
|
-
|
323
|
-
#### Use this method if:
|
324
|
-
|
325
|
-
* You want to record the current user's id at the time of an exception
|
326
|
-
* You need to send raw POST data for use in debugging
|
327
|
-
* You have any other metadata you'd like to send with an exception
|
328
|
-
|
329
|
-
#### Examples:
|
330
|
-
|
331
|
-
```ruby
|
332
|
-
Honeybadger.context({my_data: 'my value'})
|
333
|
-
|
334
|
-
# Inside a Rails controller:
|
335
|
-
before_action do
|
336
|
-
Honeybadger.context({user_id: current_user.id})
|
337
|
-
end
|
338
|
-
|
339
|
-
# Clearing global context:
|
340
|
-
Honeybadger.context.clear!
|
341
|
-
|
342
|
-
# Fetching current context
|
343
|
-
Honeybadger.get_context
|
344
|
-
```
|
345
|
-
|
346
|
-
---
|
347
|
-
|
348
|
-
|
349
|
-
### `Honeybadger.notify()`: Send an exception to Honeybadger.
|
350
|
-
|
351
|
-
You normally won't have to use this method. Honeybadger detects and reports errors automatically in Rails and other popular frameworks. But there may be times when you need to manually control exception reporting. [View full method documentation](http://www.rubydoc.info/gems/honeybadger/Honeybadger%3Anotify)
|
352
|
-
|
353
|
-
#### Use this method if:
|
354
|
-
|
355
|
-
* You've rescued an exception, but still want to report it
|
356
|
-
* You need to report an exception outside of a supported framework.
|
357
|
-
* You want complete control over what exception data is sent to us.
|
358
|
-
|
359
|
-
|
360
|
-
#### Examples:
|
361
|
-
|
362
|
-
```ruby
|
363
|
-
# Sending an exception that you've already rescued
|
364
|
-
begin
|
365
|
-
fail 'oops'
|
366
|
-
rescue => exception
|
367
|
-
Honeybadger.notify(exception)
|
368
|
-
end
|
369
|
-
```
|
370
|
-
|
371
|
-
---
|
372
|
-
|
373
|
-
### `Honeybadger.configure()`: Configure Honeybadger from Ruby
|
374
|
-
|
375
|
-
This method allows you to configure Honeybadger at runtime.
|
376
|
-
|
377
|
-
#### Use this method if:
|
378
|
-
|
379
|
-
* You want to change Honeybadger's configuration from inside Ruby rather than
|
380
|
-
(or in addition to) using the honeybadger.yml file or environment variables.
|
381
|
-
|
382
|
-
#### Examples:
|
383
|
-
|
384
|
-
```ruby
|
385
|
-
Honeybadger.configure do |config|
|
386
|
-
config.api_key = 'project api key'
|
387
|
-
config.exceptions.ignore += [CustomError]
|
388
|
-
end
|
389
|
-
```
|
390
|
-
|
391
|
-
---
|
392
|
-
|
393
|
-
### `Honeybadger.exception_filter()`: Programmatically ignore exceptions
|
394
|
-
|
395
|
-
This method lets you add a callback that will be run every time an exception is about to be reported to Honeybadger. If your callback returns a truthy value, the exception won't be reported. [View full method documentation](http://www.rubydoc.info/gems/honeybadger/Honeybadger%3Aexception_filter)
|
396
|
-
|
397
|
-
#### Use this method if:
|
398
|
-
|
399
|
-
* You need to ignore exceptions that meet complex criteria
|
400
|
-
* The built-in configuration options for filtering based on exception class and user agent aren't enough
|
401
|
-
|
402
|
-
#### Examples:
|
403
|
-
|
404
|
-
```ruby
|
405
|
-
# Here's how you might ignore exceptions based on their error message:
|
406
|
-
Honeybadger.exception_filter do |notice|
|
407
|
-
notice[:error_message] =~ /sensitive data/
|
408
|
-
end
|
409
|
-
```
|
410
|
-
|
411
|
-
You can access any attribute on the `notice` argument by using the `[]` syntax. For a full list of attributes, see the [documentation for `Notice`](http://www.rubydoc.info/gems/honeybadger/Honeybadger/Notice#%5B%5D-instance_method) Here are a few examples to get you started:
|
412
|
-
|
413
|
-
```ruby
|
414
|
-
Honeybadger.exception_filter do |notice|
|
415
|
-
notice[:exception].class < MyError &&
|
416
|
-
notice[:params][:name] =~ "bob" &&
|
417
|
-
notice[:context][:current_user_id] != 1
|
418
|
-
end
|
419
|
-
```
|
420
|
-
__WARNING:__ While it is possible to use this callback to modify the data that is reported to Honeybadger, this is not officially supported and may not be allowed in future versions of the gem.
|
421
|
-
|
422
|
-
---
|
423
|
-
|
424
|
-
### `Honeybadger.exception_fingerprint()`: Customize your error grouping.
|
425
|
-
|
426
|
-
This method lets you add a callback that should return a unique string given a `Honeybadger::Notice` instance. All notices which match the same string will be grouped together in Honeybadger.
|
427
|
-
|
428
|
-
#### Use this method if:
|
429
|
-
|
430
|
-
* You currently receive too many error notifications
|
431
|
-
* You want to group some errors together which are currently unique
|
432
|
-
* You *don't* want to group some errors which are currently grouped
|
433
|
-
|
434
|
-
#### Examples:
|
435
|
-
|
436
|
-
```ruby
|
437
|
-
Honeybadger.exception_fingerprint do |notice|
|
438
|
-
[notice[:error_class], notice[:component], notice[:backtrace].to_s].join(':')
|
439
|
-
end
|
440
|
-
```
|
441
|
-
|
442
|
-
---
|
443
|
-
|
444
|
-
### `Honeybadger.backtrace_filter()`: Filter your backtrace.
|
445
|
-
|
446
|
-
This method allows you to add a callback which modifies each line of the backtrace before a notification happens.
|
447
|
-
|
448
|
-
#### Use this method if:
|
449
|
-
|
450
|
-
* You want to change or sanitize common data in your exception backtraces
|
451
|
-
|
452
|
-
#### Examples:
|
453
|
-
|
454
|
-
```ruby
|
455
|
-
Honeybadger.backtrace_filter do |line|
|
456
|
-
line.gsub(/^\/my\/unknown\/bundle\/path/, "[GEM_ROOT]")
|
457
|
-
end
|
458
|
-
```
|
459
|
-
|
460
|
-
## Deployment Tracking
|
461
|
-
|
462
|
-
Honeybadger has an API to keep track of project deployments. Whenever you deploy, all errors for that environment will be resolved automatically. You can choose to enable or disable the auto-resolve feature from your Honeybadger project settings page.
|
463
|
-
|
464
|
-
### Capistrano Deployment Tracking
|
465
|
-
|
466
|
-
In order to track deployments using Capistrano, simply require Honeybadger's Capistrano task in your `Capfile` file:
|
467
|
-
|
468
|
-
```
|
469
|
-
require "capistrano/honeybadger"
|
470
|
-
```
|
471
|
-
|
472
|
-
If you ran the `honeybadger install` command in a project that was previously configured with Capistrano, we already added this for you.
|
473
|
-
|
474
|
-
Adding options to your _config/deploy.rb_ file allows you to customize how the deploy task is executed. The syntax for setting them looks like this:
|
475
|
-
|
476
|
-
```
|
477
|
-
set :honeybadger_env, "preprod"
|
478
|
-
```
|
479
|
-
|
480
|
-
You can use any of the following options when configuring capistrano.
|
481
|
-
|
482
|
-
| Option | |
|
483
|
-
|-------------------------- | ---- |
|
484
|
-
|`honeybadger_user` | Honeybadger will report the name of the local user who is deploying (using `whoami` or equivalent). Use this option to to report a different user.|
|
485
|
-
|`honeybadger_env` | Honeybadger reports the environment supplied by capistrano by default. Use this option to change the reported environment.|
|
486
|
-
|`honeybadger_api_key` | Honeybadger uses your configured API key by default. Use this option to override.|
|
487
|
-
|`honeybadger_async_notify` | Run deploy notification task asynchronously using `nohup`. True or False. Defaults to false.|
|
488
|
-
|`honeybadger_server` | The api endpoint that receives the deployment notification.|
|
489
|
-
|`honeybadger` | The name of the honeybadger executable. Default: "honeybadger"|
|
490
|
-
|
491
|
-
|
492
|
-
### Heroku Deployment Tracking
|
493
|
-
|
494
|
-
Deploy tracking via Heroku is implemented using Heroku's free [deploy hooks](https://devcenter.heroku.com/articles/deploy-hooks) addon. To install the addon and configure it for Honeybadger, run the following CLI command from your project root:
|
495
|
-
|
496
|
-
```
|
497
|
-
$ bundle exec honeybadger heroku install_deploy_notification
|
498
|
-
```
|
499
|
-
|
500
|
-
If the honeybadger CLI command fails for whatever reason, you can add the deploy hook manually by running:
|
501
|
-
|
502
|
-
```
|
503
|
-
$ heroku addons:add deployhooks:http --url="https://api.honeybadger.io/v1/deploys?deploy[environment]=production&deploy[local_username]={{user}}&deploy[revision]={{head}}&api_key=asdf" --app app-name
|
504
|
-
```
|
505
|
-
|
506
|
-
You should replace the api key and app-name with your own values. You may also want to change the environment (set to production by default).
|
507
|
-
|
508
|
-
|
509
|
-
### Deployment Tracking Via command line
|
510
|
-
|
511
|
-
We provide a CLI command to send deployment notifications manually:
|
512
|
-
|
513
|
-
```
|
514
|
-
bundle exec honeybadger deploy --environment=production
|
515
|
-
```
|
516
|
-
|
517
|
-
Run `bundle exec honeybadger help deploy` for all available options.
|
518
|
-
|
519
|
-
|
520
|
-
## Honeybadger CLI
|
521
|
-
|
522
|
-
The Honeybadger CLI provides a Command Line Interface for various
|
523
|
-
Honeybadger-related programs and utilities. All features are available through
|
524
|
-
the `honeybadger` command and can be used independently of Bundler/Rails.
|
525
|
-
|
526
|
-
When using the *honeybadger* gem with Bundler, run `bundle exec honeybadger`.
|
527
|
-
|
528
|
-
To use outside of bundler, install the Honeybadger gem with `gem install
|
529
|
-
honeybadger` and then run `honeybadger`.
|
530
|
-
|
531
|
-
### CLI Configuration
|
532
|
-
|
533
|
-
The `honeybadger` command optionally reads configuration from the following
|
534
|
-
locations. Each location in the list takes precedence over the previous
|
535
|
-
location:
|
536
|
-
|
537
|
-
1. ~/honeybadger.yml
|
538
|
-
2. ./config/honeybadger.yml
|
539
|
-
3. ./honeybadger.yml
|
540
|
-
4. Rails/Ruby configuration (only when called from a Rails app root)
|
541
|
-
5. Environment variables
|
542
|
-
6. Command-line flags (i.e. `--api-key`)
|
543
|
-
|
544
|
-
The following configuration options are used by the CLI when applicable:
|
545
|
-
`api_key`, `env`. See [Configuration Options](#configuration-options)
|
546
|
-
|
547
|
-
All other options must be passed as command-line flags.
|
548
|
-
|
549
|
-
### CLI Commands
|
550
|
-
|
551
|
-
The following commands are available through the `honeybadger` CLI:
|
552
|
-
|
553
|
-
| Command | Description |
|
554
|
-
| -------------------- | ----------- |
|
555
|
-
| honeybadger deploy | Notify Honeybadger of deployment |
|
556
|
-
| honeybadger exec | Execute a command. If the exit status is not 0, report the result to Honeybadger |
|
557
|
-
| honeybadger help | Describe available commands or one specific command |
|
558
|
-
| honeybadger heroku | Manage Honeybadger on Heroku |
|
559
|
-
| honeybadger install | Install Honeybadger into a new project |
|
560
|
-
| honeybadger notify | Notify Honeybadger of an error |
|
561
|
-
| honeybadger test | Send a test notification from Honeybadger |
|
562
|
-
|
563
|
-
For additional info about each command, run `honeybadger help`.
|
564
|
-
|
565
|
-
### Rails initialization
|
566
|
-
|
567
|
-
When run from the root of a Rails project, the `honeybadger` command will load
|
568
|
-
the Rails environment so that any framework/programmatic configuration is picked
|
569
|
-
up.
|
570
|
-
|
571
|
-
## Cron/command line monitoring
|
572
|
-
|
573
|
-
`honeybadger exec` can be used from the command line/terminal to monitor failed
|
574
|
-
commands. To use it, prefix any normal command with `honeybadger exec` (much
|
575
|
-
like `bundle exec`):
|
576
|
-
|
577
|
-
```sh
|
578
|
-
$ honeybadger exec my-command --my-flag
|
579
|
-
```
|
580
|
-
|
581
|
-
If the command executes successfully, honeybadger exits with code 0. It prints
|
582
|
-
any output from the command by default. To use with cron's automatic email
|
583
|
-
feature, use the `--quiet` flag, which will suppress all standard output from
|
584
|
-
the origin command unless the command fails *and* the Honeybadger notification
|
585
|
-
fails, in which case it will dump the output so that cron can send a backup
|
586
|
-
email notification.
|
587
|
-
|
588
|
-
For full usage run `honeybadger help exec`.
|
589
|
-
|
590
|
-
## Notify from the command line
|
591
|
-
|
592
|
-
To send a Honeybadger notification from the command line/terminal, use
|
593
|
-
`honeybadger notify`:
|
594
|
-
|
595
|
-
```sh
|
596
|
-
$ honeybadger notify --message "This is an error from the command line"
|
597
|
-
```
|
598
|
-
|
599
|
-
For full usage run `honeybadger help notify`.
|
600
|
-
|
601
|
-
## Reporting to multiple Honeybadger projects in the same app
|
602
|
-
|
603
|
-
To send errors to another Honeybadger project, configure an additional agent:
|
604
|
-
|
605
|
-
```ruby
|
606
|
-
OtherBadger = Honeybadger::Agent.new
|
607
|
-
|
608
|
-
OtherBadger.configure do |config|
|
609
|
-
config.api_key = 'project api key'
|
610
|
-
end
|
611
|
-
|
612
|
-
begin
|
613
|
-
# Failing code
|
614
|
-
rescue => exception
|
615
|
-
OtherBadger.notify(exception)
|
616
|
-
end
|
617
|
-
```
|
618
|
-
|
619
|
-
Agents do not use the global honeybadger.yml or environment variable
|
620
|
-
configuration and must be configured manually after they are instantiated.
|
621
|
-
|
622
|
-
## Custom Error Pages
|
623
|
-
|
624
|
-
The Honeybadger gem has a few special tags that it looks for whenever you render an error page. These can be used to display extra information about the error, or to ask the user for information about how they triggered the error.
|
625
|
-
|
626
|
-
### Displaying Error ID
|
627
|
-
|
628
|
-
When an error is sent to Honeybadger, our API returns a unique UUID for the occurrence within your project. This UUID can be automatically displayed for reference on Rails error pages (e.g. `public/500.html`) or any rack output by including the `Honeybadger::UserInformer` middleware.
|
629
|
-
|
630
|
-
To include the error id, simply place this magic HTML comment on your error page:
|
631
|
-
|
632
|
-
```html
|
633
|
-
<!-- HONEYBADGER ERROR -->
|
634
|
-
```
|
635
|
-
|
636
|
-
By default, we will replace this tag with:
|
637
|
-
|
638
|
-
```
|
639
|
-
Honeybadger Error {{error_id}}
|
640
|
-
```
|
641
|
-
|
642
|
-
Where `{{error_id}}` is the UUID. You can customize this output by overriding the `user_informer.info` option in your honeybadger.yml file (you can also enabled/disable the middleware):
|
643
|
-
|
644
|
-
```yaml
|
645
|
-
user_informer:
|
646
|
-
enabled: true
|
647
|
-
info: "Error ID: {{error_id}}"
|
648
|
-
```
|
649
|
-
|
650
|
-
You can use that UUID to load the error at the site by going to [https://www.honeybadger.io/notice/UUID](https://www.honeybadger.io/notice/UUID).
|
651
|
-
|
652
|
-
### Collecting User Feedback
|
653
|
-
|
654
|
-
When an error is sent to Honeybadger, an HTML form can be generated so users can fill out relevant information that led up to that error. Feedback responses are displayed inline in the comments section on the fault detail page.
|
655
|
-
|
656
|
-
To include a user feedback form on your error page, simply add this magic HTML comment:
|
657
|
-
|
658
|
-
```html
|
659
|
-
<!-- HONEYBADGER FEEDBACK -->
|
660
|
-
```
|
661
|
-
You can change the text displayed in the form via the Rails internationalization system. Here's an example:
|
662
|
-
|
663
|
-
```yaml
|
664
|
-
# config/locales/en.yml
|
665
|
-
en:
|
666
|
-
honeybadger:
|
667
|
-
feedback:
|
668
|
-
heading: "Care to help us fix this?"
|
669
|
-
explanation: "Any information you can provide will help us fix the problem."
|
670
|
-
submit: "Send"
|
671
|
-
thanks: "Thanks for the feedback!"
|
672
|
-
labels:
|
673
|
-
name: "Your name"
|
674
|
-
email: "Your email address"
|
675
|
-
comment: "Comment (required)"
|
676
|
-
```
|
677
|
-
|
678
|
-
## Testing Honeybadger in your integration tests
|
679
|
-
|
680
|
-
It is possible to test Honeybadger's integration with your application using the
|
681
|
-
included test backend.
|
682
|
-
|
683
|
-
The test backend replaces the default server backend with a stub that records
|
684
|
-
error notices rather than sending them, allowing all but the HTTP notification
|
685
|
-
itself to be verified. Alternatively, you could use something like
|
686
|
-
[WebMock](https://github.com/bblimke/webmock) to perform a similar test using
|
687
|
-
the "server" backend.
|
688
|
-
|
689
|
-
### Configuring the test backend
|
690
|
-
|
691
|
-
To use the test backend, set the `backend` configuration option to "test" in
|
692
|
-
honeybadger.yml for your test environment only:
|
693
|
-
|
694
|
-
```yaml
|
695
|
-
api_key: 'project api key'
|
696
|
-
test:
|
697
|
-
backend: test
|
698
|
-
```
|
699
|
-
|
700
|
-
You can also use the *HONEYBADGER_BACKEND* environment variable to configure the
|
701
|
-
test backend. Note that you must also configure your API key for the test to
|
702
|
-
succeed.
|
703
|
-
|
704
|
-
|
705
|
-
### Writing the integration test
|
706
|
-
|
707
|
-
The test backend can be used in any testing framework to test any code which
|
708
|
-
reports an error with `Honeybadger.notify`. A common scenario is to test the
|
709
|
-
Rails-integration which reports exceptions in a Rails controller automatically.
|
710
|
-
|
711
|
-
The following example uses RSpec to test error notification in a Rails
|
712
|
-
controller.
|
713
|
-
|
714
|
-
First, create the controller:
|
715
|
-
|
716
|
-
```ruby
|
717
|
-
# app/controllers/honeybadger_test_controller.rb
|
718
|
-
class HoneybadgerTestController < ApplicationController
|
719
|
-
ERROR = RuntimeError.new("testing reporting an error to Honeybadger")
|
720
|
-
|
721
|
-
def index
|
722
|
-
raise ERROR
|
723
|
-
end
|
724
|
-
end
|
725
|
-
```
|
726
|
-
|
727
|
-
Next, create a route. For security, it's a good idea to enable the route only in
|
728
|
-
the test environment:
|
729
|
-
|
730
|
-
```ruby
|
731
|
-
# config/routes.rb
|
732
|
-
|
733
|
-
# ...
|
734
|
-
get '/test/honeybadger' => 'honeybadger_test#index' if Rails.env.test?
|
735
|
-
```
|
736
|
-
|
737
|
-
Finally, create the integration test:
|
738
|
-
|
739
|
-
```ruby
|
740
|
-
# spec/features/honeybadger_spec.rb
|
741
|
-
require 'rails_helper'
|
742
|
-
|
743
|
-
describe "error notification" do
|
744
|
-
it "notifies Honeybadger" do
|
745
|
-
expect {
|
746
|
-
# Code to test goes here:
|
747
|
-
expect { visit '/test/honeybadger' }.to raise_error(HoneybadgerTestController::ERROR)
|
748
|
-
|
749
|
-
# Important: `Honeybadger.flush` ensures that asynchronous notifications
|
750
|
-
# are delivered before the test's remaining expectations are verified.
|
751
|
-
Honeybadger.flush
|
752
|
-
}.to change(Honeybadger::Backend::Test.notifications[:notices], :size).by(1)
|
753
|
-
expect(Honeybadger::Backend::Test.notifications[:notices].first.error_message).to eq('testing reporting an error to Honeybadger')
|
754
|
-
end
|
755
|
-
end
|
756
|
-
```
|
757
|
-
|
758
|
-
## Troubleshooting
|
759
|
-
|
760
|
-
See [TROUBLESHOOTING.md](https://github.com/honeybadger-io/honeybadger-ruby/blob/master/TROUBLESHOOTING.md)
|
12
|
+
For comprehensive documentation and support, [check out our documentation site](https://docs.honeybadger.io/ruby/index.html).
|
761
13
|
|
762
14
|
## Changelog
|
763
15
|
|