bugsnag 2.8.12 → 2.8.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/README.md +85 -546
- data/VERSION +1 -1
- data/docs/Configuration.md +239 -0
- data/docs/Notification Options.md +269 -0
- data/docs/README.md +14 -0
- data/lib/bugsnag/configuration.rb +2 -0
- data/lib/bugsnag/delivery/thread_queue.rb +6 -8
- data/lib/bugsnag/deploy.rb +0 -1
- data/lib/bugsnag/notification.rb +13 -2
- data/lib/bugsnag/railtie.rb +2 -2
- data/lib/bugsnag/tasks/bugsnag.rake +1 -1
- data/spec/notification_spec.rb +13 -0
- data/spec/spec_helper.rb +5 -5
- metadata +26 -23
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.8.
|
1
|
+
2.8.13
|
@@ -0,0 +1,239 @@
|
|
1
|
+
# `bugsnag-ruby` Configuration
|
2
|
+
|
3
|
+
To configure additional Bugsnag settings, use the block syntax and set any
|
4
|
+
settings you need on the `config` block variable. For example:
|
5
|
+
|
6
|
+
```ruby
|
7
|
+
Bugsnag.configure do |config|
|
8
|
+
config.api_key = "your-api-key-here"
|
9
|
+
config.notify_release_stages = ["production", "development"]
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
13
|
+
## Available Options
|
14
|
+
|
15
|
+
### `api_key`
|
16
|
+
|
17
|
+
Your Bugsnag API key (required).
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
config.api_key = "your-api-key-here"
|
21
|
+
```
|
22
|
+
|
23
|
+
### `app_type`
|
24
|
+
|
25
|
+
You can set the type of application executing the current code by using
|
26
|
+
`app_type`:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
config.app_type = "resque"
|
30
|
+
```
|
31
|
+
|
32
|
+
This is usually used to represent if you are running in a Rails server, Sidekiq
|
33
|
+
job or Rake task for example. Bugsnag will automatically detect most application
|
34
|
+
types for you.
|
35
|
+
|
36
|
+
### `app_version`
|
37
|
+
|
38
|
+
If you want to track in which versions of your application each exception
|
39
|
+
happens, you can set `app_version`. This is set to `nil` by default.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
config.app_version = "2.5.1"
|
43
|
+
```
|
44
|
+
|
45
|
+
### `auto_notify`
|
46
|
+
|
47
|
+
By default, we will automatically notify Bugsnag of any fatal exceptions
|
48
|
+
in your application. If you want to stop this from happening, you can set
|
49
|
+
`auto_notify`:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
config.auto_notify = false
|
53
|
+
```
|
54
|
+
|
55
|
+
### `endpoint`
|
56
|
+
|
57
|
+
By default, we'll send crashes to *notify.bugsnag.com* to display them on
|
58
|
+
your dashboard. If you are using *Bugsnag Enterprise* you'll need to set
|
59
|
+
this to be your *Event Server* endpoint, for example:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
config.endpoint = "bugsnag.example.com:49000"
|
63
|
+
```
|
64
|
+
|
65
|
+
### `ignore_classes`
|
66
|
+
|
67
|
+
Sets for which exception classes we should not send exceptions to bugsnag.com.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
config.ignore_classes << "ActiveRecord::StatementInvalid"
|
71
|
+
```
|
72
|
+
|
73
|
+
You can also provide a lambda function here to ignore by other exception
|
74
|
+
attributes or by a regex:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
config.ignore_classes << lambda {|ex| ex.message =~ /timeout/}
|
78
|
+
```
|
79
|
+
|
80
|
+
By default, `ignore_classes` contains the following:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
[
|
84
|
+
"ActiveRecord::RecordNotFound",
|
85
|
+
"ActionController::RoutingError",
|
86
|
+
"ActionController::InvalidAuthenticityToken",
|
87
|
+
"CGI::Session::CookieStore::TamperedWithCookie",
|
88
|
+
"ActionController::UnknownAction",
|
89
|
+
"AbstractController::ActionNotFound"
|
90
|
+
]
|
91
|
+
```
|
92
|
+
|
93
|
+
### `ignore_user_agents`
|
94
|
+
|
95
|
+
Sets an array of Regexps that can be used to ignore exceptions from
|
96
|
+
certain user agents.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
config.ignore_user_agents << %r{Chrome}
|
100
|
+
```
|
101
|
+
|
102
|
+
By default, `ignore_user_agents` is empty, so exceptions caused by all
|
103
|
+
user agents are reported.
|
104
|
+
|
105
|
+
### `logger`
|
106
|
+
|
107
|
+
Sets which logger to use for Bugsnag log messages. In rails apps, this is
|
108
|
+
automatically set to use `Rails.logger`, otherwise it will be set to
|
109
|
+
`Logger.new(STDOUT)`.
|
110
|
+
|
111
|
+
### `middleware`
|
112
|
+
|
113
|
+
Provides access to the middleware stack, see the
|
114
|
+
[Bugsnag Middleware](#bugsnag-middleware) section below for details.
|
115
|
+
|
116
|
+
### `notify_release_stages`
|
117
|
+
|
118
|
+
By default, we will notify Bugsnag of exceptions that happen in any
|
119
|
+
`release_stage`. If you would like to change which release stages
|
120
|
+
notify Bugsnag of exceptions you can set `notify_release_stages`:
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
config.notify_release_stages = ["production", "development"]
|
124
|
+
```
|
125
|
+
|
126
|
+
### `params_filters`
|
127
|
+
|
128
|
+
Sets which keys should be filtered out from `params` hashes before sending
|
129
|
+
them to Bugsnag. Use this if you want to ensure you don't send sensitive data
|
130
|
+
such as passwords, and credit card numbers to our servers. You can add both
|
131
|
+
strings and regular expressions to this array. When adding strings, keys which
|
132
|
+
*contain* the string will be filtered. When adding regular expressions, any
|
133
|
+
keys which *match* the regular expression will be filtered.
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
config.params_filters += ["credit_card_number", /^password$/]
|
137
|
+
```
|
138
|
+
|
139
|
+
By default, `params_filters` is set to `[/authorization/i, /cookie/i,
|
140
|
+
/password/i, /secret/i]`, and for rails apps, imports all values from
|
141
|
+
`Rails.configuration.filter_parameters`.
|
142
|
+
|
143
|
+
<!-- Custom anchor for linking from alerts -->
|
144
|
+
<div id="set-project-root"></div>
|
145
|
+
### `project_root`
|
146
|
+
|
147
|
+
We mark stacktrace lines as `inProject` if they come from files inside your
|
148
|
+
`project_root`. In rails apps this value is automatically set to `RAILS_ROOT`,
|
149
|
+
otherwise you should set it manually:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
config.project_root = "/var/www/myproject"
|
153
|
+
```
|
154
|
+
|
155
|
+
### `proxy_host`
|
156
|
+
|
157
|
+
Sets the address of the HTTP proxy that should be used for requests to bugsnag.
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
config.proxy_host = "10.10.10.10"
|
161
|
+
```
|
162
|
+
|
163
|
+
### `proxy_password`
|
164
|
+
|
165
|
+
Sets the password for the user that should be used to send requests to the HTTP proxy for requests to bugsnag.
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
config.proxy_password = "proxy_secret_password_here"
|
169
|
+
```
|
170
|
+
|
171
|
+
### `proxy_port`
|
172
|
+
|
173
|
+
Sets the port of the HTTP proxy that should be used for requests to bugsnag.
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
config.proxy_port = 1089
|
177
|
+
```
|
178
|
+
|
179
|
+
### `proxy_user`
|
180
|
+
|
181
|
+
Sets the user that should be used to send requests to the HTTP proxy for requests to bugsnag.
|
182
|
+
|
183
|
+
```ruby
|
184
|
+
config.proxy_user = "proxy_user"
|
185
|
+
```
|
186
|
+
|
187
|
+
### `release_stage`
|
188
|
+
|
189
|
+
If you would like to distinguish between errors that happen in different
|
190
|
+
stages of the application release process (development, production, etc)
|
191
|
+
you can set the `release_stage` that is reported to Bugsnag.
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
config.release_stage = "development"
|
195
|
+
```
|
196
|
+
|
197
|
+
In rails apps this value is automatically set from `RAILS_ENV`, and in rack
|
198
|
+
apps it is automatically set to `RACK_ENV`. Otherwise the default is
|
199
|
+
"production".
|
200
|
+
|
201
|
+
### `send_environment`
|
202
|
+
|
203
|
+
Bugsnag can transmit your rack environment to help diagnose issues. This environment
|
204
|
+
can sometimes contain private information so Bugsnag does not transmit by default. To
|
205
|
+
send your rack environment, set the `send_environment` option to `true`.
|
206
|
+
|
207
|
+
```ruby
|
208
|
+
config.send_environment = true
|
209
|
+
```
|
210
|
+
|
211
|
+
### `send_code`
|
212
|
+
|
213
|
+
Bugsnag automatically sends a small snippet of the code that crashed to help you diagnose
|
214
|
+
even faster from within your dashboard. If you don't want to send this snippet you can
|
215
|
+
set the `send_code` option to `false`.
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
config.send_code = false
|
219
|
+
```
|
220
|
+
|
221
|
+
### `timeout`
|
222
|
+
By default the timeout for posting errors to Bugsnag is 15 seconds, to change this
|
223
|
+
you can set the `timeout`:
|
224
|
+
|
225
|
+
```ruby
|
226
|
+
config.timeout = 10
|
227
|
+
```
|
228
|
+
|
229
|
+
### `use_ssl`
|
230
|
+
|
231
|
+
Enforces all communication with bugsnag.com be made via ssl. You can turn
|
232
|
+
this off if necessary.
|
233
|
+
|
234
|
+
```ruby
|
235
|
+
config.use_ssl = false
|
236
|
+
```
|
237
|
+
|
238
|
+
By default, `use_ssl` is set to true.
|
239
|
+
|
@@ -0,0 +1,269 @@
|
|
1
|
+
# `bugsnag-ruby` Notification Options
|
2
|
+
|
3
|
+
It is often useful to send additional meta-data about your app, such as
|
4
|
+
information about the currently logged in user, along with any
|
5
|
+
exceptions, to help debug problems.
|
6
|
+
|
7
|
+
* [Notification Object](#notification-object)
|
8
|
+
- [Instance Methods](#instance-methods)
|
9
|
+
- [`Bugsnag::MetaData` Exception Mixin](#exception-mixin)
|
10
|
+
* [Handled Notification Options](#handled-notification-options)
|
11
|
+
* [Framework-specific Configuration](#framework-specific-configuration)
|
12
|
+
- [Rails Apps](#rails-apps)
|
13
|
+
- [Rails API Apps](#rails-api-apps)
|
14
|
+
- [Other Ruby Apps](#other-ruby-apps)
|
15
|
+
|
16
|
+
## Notification Object
|
17
|
+
|
18
|
+
The notification object is passed to all [before bugsnag notify](#sending-custom-data-with-exceptions)
|
19
|
+
callbacks and is used to manipulate the error report before it is transmitted.
|
20
|
+
|
21
|
+
### Instance Methods
|
22
|
+
|
23
|
+
#### `add_tab`
|
24
|
+
|
25
|
+
Call add_tab on a notification object to add a tab to the error report so that
|
26
|
+
it would appear on your dashboard.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
notif.add_tab(:user_info, {
|
30
|
+
name: current_user.name
|
31
|
+
})
|
32
|
+
```
|
33
|
+
|
34
|
+
The first parameter is the tab name that will appear in the error report and the
|
35
|
+
second is the key, value list that will be displayed in the tab.
|
36
|
+
|
37
|
+
#### `remove_tab`
|
38
|
+
|
39
|
+
Removes a tab completely from the error report
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
notif.remove_tab(:request)
|
43
|
+
```
|
44
|
+
|
45
|
+
#### `ignore!`
|
46
|
+
|
47
|
+
Calling ignore! on a notification object will cause the notification to not be
|
48
|
+
sent to bugsnag. This means that you can choose dynamically not to send an error
|
49
|
+
depending on application state or the error itself.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
notif.ignore! if foo == 'bar'
|
53
|
+
```
|
54
|
+
|
55
|
+
#### `grouping_hash`
|
56
|
+
|
57
|
+
Sets the grouping hash of the error report. All errors with the same grouping
|
58
|
+
hash are grouped together. This is an advanced usage of the library and
|
59
|
+
mis-using it will cause your errors not to group properly in your dashboard.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
notif.grouping_hash = "#{exception.message}#{exception.class}"
|
63
|
+
```
|
64
|
+
|
65
|
+
#### `severity`
|
66
|
+
|
67
|
+
Set the severity of the error. Severity can be `error`, `warning` or `info`.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
notif.severity = "error"
|
71
|
+
```
|
72
|
+
|
73
|
+
#### `context`
|
74
|
+
|
75
|
+
Set the context of the error report. This is notionally the location of the
|
76
|
+
error and should be populated automatically. Context is displayed in the
|
77
|
+
dashboard prominently.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
notif.context = "billing"
|
81
|
+
```
|
82
|
+
|
83
|
+
#### `user`
|
84
|
+
|
85
|
+
You can set or read the user with the user property of the notification. The
|
86
|
+
user will be a hash of `email`, `id` and `name`.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
notif.user = {
|
90
|
+
id: current_user.id,
|
91
|
+
email: current_user.email,
|
92
|
+
name: current_user.name
|
93
|
+
}
|
94
|
+
```
|
95
|
+
|
96
|
+
#### `exceptions`
|
97
|
+
|
98
|
+
Allows you to read the exceptions that will be combined into the report.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
puts "#{notif.exceptions.first.message} found!"
|
102
|
+
```
|
103
|
+
|
104
|
+
#### `meta_data`
|
105
|
+
|
106
|
+
Provides access to the meta_data in the error report.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
notif.ignore! if notif.meta_data[:sidekiq][:retry_count] > 2
|
110
|
+
```
|
111
|
+
|
112
|
+
### Exception Mixin
|
113
|
+
|
114
|
+
If you include the `Bugsnag::MetaData` module into your own exceptions, you can
|
115
|
+
associate meta data with a particular exception.
|
116
|
+
|
117
|
+
```ruby
|
118
|
+
class MyCustomException < Exception
|
119
|
+
include Bugsnag::MetaData
|
120
|
+
end
|
121
|
+
|
122
|
+
exception = MyCustomException.new("It broke!")
|
123
|
+
exception.bugsnag_meta_data = {
|
124
|
+
:user_info => {
|
125
|
+
name: current_user.name
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
raise exception
|
130
|
+
```
|
131
|
+
|
132
|
+
## Handled Notification Options
|
133
|
+
|
134
|
+
Non-fatal exception notifications can send additional metadata in when being
|
135
|
+
sent via `Bugsnag.notify` including setting the severity and custom data.
|
136
|
+
|
137
|
+
#### Severity
|
138
|
+
|
139
|
+
You can set the severity of an error in Bugsnag by including the severity option when
|
140
|
+
notifying bugsnag of the error,
|
141
|
+
|
142
|
+
```ruby
|
143
|
+
Bugsnag.notify(RuntimeError.new("Something broke"), {
|
144
|
+
:severity => "error",
|
145
|
+
})
|
146
|
+
```
|
147
|
+
|
148
|
+
Valid severities are `error`, `warning` and `info`.
|
149
|
+
|
150
|
+
Severity is displayed in the dashboard and can be used to filter the error list.
|
151
|
+
By default all crashes (or unhandled exceptions) are set to `error` and all
|
152
|
+
`Bugsnag.notify` calls default to `warning`.
|
153
|
+
|
154
|
+
#### Multiple projects
|
155
|
+
|
156
|
+
If you want to divide errors into multiple Bugsnag projects, you can specify the API key as a parameter to `Bugsnag.notify`:
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
rescue => e
|
160
|
+
Bugsnag.notify e, api_key: "your-api-key-here"
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
#### Custom Metadata
|
165
|
+
|
166
|
+
You can also send additional meta-data with your exception:
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
Bugsnag.notify(RuntimeError.new("Something broke"), {
|
170
|
+
:user => {
|
171
|
+
:username => "bob-hoskins",
|
172
|
+
:registered_user => true
|
173
|
+
}
|
174
|
+
})
|
175
|
+
```
|
176
|
+
|
177
|
+
#### Custom Grouping via `grouping_hash`
|
178
|
+
|
179
|
+
If you want to override Bugsnag's grouping algorithm, you can specify a grouping hash key as a parameter to `Bugsnag.notify`:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
rescue => e
|
183
|
+
Bugsnag.notify e, grouping_hash: "this-is-my-grouping-hash"
|
184
|
+
end
|
185
|
+
```
|
186
|
+
|
187
|
+
All errors with the same groupingHash will be grouped together within the bugsnag dashboard.
|
188
|
+
|
189
|
+
## Framework-specific Configuration
|
190
|
+
|
191
|
+
### Rails Apps
|
192
|
+
|
193
|
+
By default Bugsnag includes some information automatically. For example, we
|
194
|
+
send all the HTTP headers for requests. Additionally if you're using Warden or
|
195
|
+
Devise, the id, name and email of the current user are sent.
|
196
|
+
|
197
|
+
To send additional information, in any rails controller you can define a
|
198
|
+
`before_bugsnag_notify` callback, which allows you to add this additional data
|
199
|
+
by calling `add_tab` on the exception notification object. Please see the
|
200
|
+
[Notification Object](#notification-object) for details on the notification
|
201
|
+
parameter.
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
class MyController < ApplicationController
|
205
|
+
# Define the filter
|
206
|
+
before_bugsnag_notify :add_user_info_to_bugsnag
|
207
|
+
|
208
|
+
# Your controller code here
|
209
|
+
|
210
|
+
private
|
211
|
+
def add_user_info_to_bugsnag(notif)
|
212
|
+
# Set the user that this bug affected
|
213
|
+
# Email, name and id are searchable on bugsnag.com
|
214
|
+
notif.user = {
|
215
|
+
email: current_user.email,
|
216
|
+
name: current_user.name,
|
217
|
+
id: current_user.id
|
218
|
+
}
|
219
|
+
|
220
|
+
# Add some app-specific data which will be displayed on a custom
|
221
|
+
# "Diagnostics" tab on each error page on bugsnag.com
|
222
|
+
notif.add_tab(:diagnostics, {
|
223
|
+
product: current_product.name
|
224
|
+
})
|
225
|
+
end
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
229
|
+
### Rails API Apps
|
230
|
+
|
231
|
+
If you are building an API using the
|
232
|
+
[rails-api](https://github.com/rails-api/rails-api) gem, your controllers will
|
233
|
+
inherit from `ActionController::API` instead of `ActionController::Base`.
|
234
|
+
|
235
|
+
In this case, the `before_bugsnag_notify` filter will not be automatically
|
236
|
+
available in your controllers. In order to use it, you will need to include
|
237
|
+
the module `Bugsnag::Rails::ControllerMethods`.
|
238
|
+
|
239
|
+
```ruby
|
240
|
+
class ApplicationController < ActionController::API
|
241
|
+
|
242
|
+
# Include module which defines the before_bugsnag_notify filter
|
243
|
+
include Bugsnag::Rails::ControllerMethods
|
244
|
+
|
245
|
+
# Other code here
|
246
|
+
end
|
247
|
+
```
|
248
|
+
|
249
|
+
### Other Ruby Apps
|
250
|
+
|
251
|
+
In other ruby apps, you can provide lambda functions to execute before any
|
252
|
+
`Bugsnag.notify` calls as follows. Don't forget to clear the callbacks at the
|
253
|
+
end of each request or session. In Rack applications like Sinatra, this is
|
254
|
+
automatically done for you.
|
255
|
+
|
256
|
+
```ruby
|
257
|
+
# Set a before notify callback
|
258
|
+
Bugsnag.before_notify_callbacks << lambda {|notif|
|
259
|
+
notif.add_tab(:user_info, {
|
260
|
+
name: current_user.name
|
261
|
+
})
|
262
|
+
}
|
263
|
+
|
264
|
+
# Your app code here
|
265
|
+
|
266
|
+
# Clear the callbacks
|
267
|
+
Bugsnag.before_notify_callbacks.clear
|
268
|
+
```
|
269
|
+
|