bugsnag 1.2.17 → 1.2.18
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/README.md +57 -37
- data/VERSION +1 -1
- data/bugsnag.gemspec +2 -1
- data/lib/bugsnag.rb +5 -4
- data/lib/bugsnag/meta_data.rb +7 -0
- data/lib/bugsnag/notification.rb +59 -35
- data/spec/notification_spec.rb +89 -2
- metadata +3 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -3,12 +3,12 @@ Bugsnag Notifier for Ruby
|
|
3
3
|
|
4
4
|
The Bugsnag Notifier for Ruby gives you instant notification of exceptions
|
5
5
|
thrown from your **Rails**, **Sinatra**, **Rack** or **plain Ruby** app.
|
6
|
-
Any uncaught exceptions will trigger a notification to be sent to your
|
6
|
+
Any uncaught exceptions will trigger a notification to be sent to your
|
7
7
|
Bugsnag project.
|
8
8
|
|
9
|
-
[Bugsnag](http://bugsnag.com) captures errors in real-time from your web,
|
10
|
-
mobile and desktop applications, helping you to understand and resolve them
|
11
|
-
as fast as possible. [Create a free account](http://bugsnag.com) to start
|
9
|
+
[Bugsnag](http://bugsnag.com) captures errors in real-time from your web,
|
10
|
+
mobile and desktop applications, helping you to understand and resolve them
|
11
|
+
as fast as possible. [Create a free account](http://bugsnag.com) to start
|
12
12
|
capturing exceptions from your applications.
|
13
13
|
|
14
14
|
|
@@ -59,13 +59,13 @@ How to Install
|
|
59
59
|
Sending Custom Data With Exceptions
|
60
60
|
-----------------------------------
|
61
61
|
|
62
|
-
It is often useful to send additional meta-data about your app, such as
|
62
|
+
It is often useful to send additional meta-data about your app, such as
|
63
63
|
information about the currently logged in user, along with any
|
64
|
-
exceptions, to help debug problems.
|
64
|
+
exceptions, to help debug problems.
|
65
65
|
|
66
66
|
### Rails Apps
|
67
67
|
|
68
|
-
In any rails controller you can define a `before_bugsnag_notify` callback,
|
68
|
+
In any rails controller you can define a `before_bugsnag_notify` callback,
|
69
69
|
which allows you to add this additional data by calling `add_tab` on the
|
70
70
|
exception notification object.
|
71
71
|
|
@@ -89,7 +89,7 @@ end
|
|
89
89
|
|
90
90
|
### Other Ruby Apps
|
91
91
|
|
92
|
-
In other ruby apps, you can provide lambda functions to execute before any
|
92
|
+
In other ruby apps, you can provide lambda functions to execute before any
|
93
93
|
`Bugsnag.notify` calls as follows. Don't forget to clear the callbacks at the
|
94
94
|
end of each request or session.
|
95
95
|
|
@@ -107,6 +107,26 @@ Bugsnag.before_notify_callbacks << lambda {|notif|
|
|
107
107
|
Bugsnag.before_notify_callbacks.clear
|
108
108
|
```
|
109
109
|
|
110
|
+
### Exceptions with Meta Data
|
111
|
+
|
112
|
+
If you include the `Bugsnag::MetaData` module into your own exceptions, you can
|
113
|
+
associate meta data with a paticular exception.
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
class MyCustomException < Exception
|
117
|
+
include Bugsnag::MetaData
|
118
|
+
end
|
119
|
+
|
120
|
+
exception = MyCustomException.new("It broke!")
|
121
|
+
exception.bugsnag_meta_data = {
|
122
|
+
:user_info => {
|
123
|
+
name: current_user.name
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
raise exception
|
128
|
+
```
|
129
|
+
|
110
130
|
You can read more about how callbacks work in the
|
111
131
|
[Bugsnag Middleware](#bugsnag-middleware) documentation below.
|
112
132
|
|
@@ -162,18 +182,18 @@ you can set the `release_stage` that is reported to Bugsnag.
|
|
162
182
|
```ruby
|
163
183
|
config.release_stage = "development"
|
164
184
|
```
|
165
|
-
|
185
|
+
|
166
186
|
In rails apps this value is automatically set from `RAILS_ENV`, and in rack
|
167
|
-
apps it is automatically set to `RACK_ENV`. Otherwise the default is
|
187
|
+
apps it is automatically set to `RACK_ENV`. Otherwise the default is
|
168
188
|
"production".
|
169
189
|
|
170
190
|
###notify_release_stages
|
171
191
|
|
172
|
-
By default, we will only notify Bugsnag of exceptions that happen when
|
173
|
-
your `release_stage` is set to be "production". If you would like to
|
192
|
+
By default, we will only notify Bugsnag of exceptions that happen when
|
193
|
+
your `release_stage` is set to be "production". If you would like to
|
174
194
|
change which release stages notify Bugsnag of exceptions you can
|
175
195
|
set `notify_release_stages`:
|
176
|
-
|
196
|
+
|
177
197
|
```ruby
|
178
198
|
config.notify_release_stages = ["production", "development"]
|
179
199
|
```
|
@@ -183,7 +203,7 @@ config.notify_release_stages = ["production", "development"]
|
|
183
203
|
By default, we will automatically notify Bugsnag of any fatal exceptions
|
184
204
|
in your application. If you want to stop this from happening, you can set
|
185
205
|
`auto_notify`:
|
186
|
-
|
206
|
+
|
187
207
|
```ruby
|
188
208
|
config.auto_notify = false
|
189
209
|
```
|
@@ -210,7 +230,7 @@ config.project_root = "/var/www/myproject"
|
|
210
230
|
|
211
231
|
###app_version
|
212
232
|
|
213
|
-
If you want to track which versions of your application each exception
|
233
|
+
If you want to track which versions of your application each exception
|
214
234
|
happens in, you can set `app_version`. This is set to `nil` by default.
|
215
235
|
|
216
236
|
```ruby
|
@@ -220,8 +240,8 @@ config.app_version = "2.5.1"
|
|
220
240
|
###params_filters
|
221
241
|
|
222
242
|
Sets the strings to filter out from the `params` hashes before sending
|
223
|
-
them to Bugsnag. Use this if you want to ensure you don't send
|
224
|
-
sensitive data such as passwords, and credit card numbers to our
|
243
|
+
them to Bugsnag. Use this if you want to ensure you don't send
|
244
|
+
sensitive data such as passwords, and credit card numbers to our
|
225
245
|
servers. Any keys which contain these strings will be filtered.
|
226
246
|
|
227
247
|
```ruby
|
@@ -238,7 +258,7 @@ Sets for which exception classes we should not send exceptions to bugsnag.com.
|
|
238
258
|
config.ignore_classes << "ActiveRecord::StatementInvalid"
|
239
259
|
```
|
240
260
|
|
241
|
-
You can also provide a lambda function here to ignore by other exception
|
261
|
+
You can also provide a lambda function here to ignore by other exception
|
242
262
|
attributes or by a regex:
|
243
263
|
|
244
264
|
```ruby
|
@@ -260,7 +280,7 @@ By default, `ignore_classes` contains the following:
|
|
260
280
|
|
261
281
|
###logger
|
262
282
|
|
263
|
-
Sets which logger to use for Bugsnag log messages. In rails apps, this is
|
283
|
+
Sets which logger to use for Bugsnag log messages. In rails apps, this is
|
264
284
|
automatically set to use `Rails.logger`, otherwise it will be set to
|
265
285
|
`Logger.new(STDOUT)`.
|
266
286
|
|
@@ -273,12 +293,12 @@ Provides access to the middleware stack, see the
|
|
273
293
|
Bugsnag Middleware
|
274
294
|
------------------
|
275
295
|
|
276
|
-
The Bugsnag Notifier for Ruby provides its own middleware system, similar to
|
277
|
-
the one used in Rack applications. Middleware allows you to execute code
|
278
|
-
before and after an exception is sent to bugsnag.com, so you can do things
|
296
|
+
The Bugsnag Notifier for Ruby provides its own middleware system, similar to
|
297
|
+
the one used in Rack applications. Middleware allows you to execute code
|
298
|
+
before and after an exception is sent to bugsnag.com, so you can do things
|
279
299
|
such as:
|
280
300
|
|
281
|
-
- Send application-specific information along with exceptions, eg. the name
|
301
|
+
- Send application-specific information along with exceptions, eg. the name
|
282
302
|
of the currently logged in user,
|
283
303
|
- Write exception information to your internal logging system.
|
284
304
|
|
@@ -317,7 +337,7 @@ for some real examples of middleware in action.
|
|
317
337
|
Deploy Tracking
|
318
338
|
---------------
|
319
339
|
|
320
|
-
Bugsnag allows you to track deploys of your apps. By sending the
|
340
|
+
Bugsnag allows you to track deploys of your apps. By sending the
|
321
341
|
source revision or application version to bugsnag.com when you deploy a new
|
322
342
|
version of your app, you'll be able to see which deploy each error was
|
323
343
|
introduced in.
|
@@ -341,8 +361,8 @@ your deploy scripts.
|
|
341
361
|
rake bugsnag:deploy BUGSNAG_REVISION=source-control-revision BUGSNAG_RELEASE_STAGE=production
|
342
362
|
```
|
343
363
|
|
344
|
-
The bugsnag rake tasks will be automatically available for Rails 3
|
345
|
-
apps, to make the rake tasks available in other apps, add the following to
|
364
|
+
The bugsnag rake tasks will be automatically available for Rails 3
|
365
|
+
apps, to make the rake tasks available in other apps, add the following to
|
346
366
|
your `Rakefile`:
|
347
367
|
|
348
368
|
```ruby
|
@@ -354,24 +374,24 @@ require "bugsnag/tasks"
|
|
354
374
|
You can set the following environmental variables to override or specify
|
355
375
|
additional deploy information:
|
356
376
|
|
357
|
-
- **BUGSNAG_RELEASE_STAGE** -
|
377
|
+
- **BUGSNAG_RELEASE_STAGE** -
|
358
378
|
The release stage (eg, production, staging) currently being deployed.
|
359
379
|
This is set automatically from your Bugsnag settings or rails/rack
|
360
380
|
environment.
|
361
381
|
|
362
|
-
- **BUGSNAG_API_KEY** -
|
382
|
+
- **BUGSNAG_API_KEY** -
|
363
383
|
Your Bugsnag API key. This is set automatically from your Bugsnag
|
364
384
|
settings in your app.
|
365
|
-
|
366
|
-
- **BUGSNAG_REPOSITORY** -
|
367
|
-
The repository from which you are deploying the code. This is set
|
385
|
+
|
386
|
+
- **BUGSNAG_REPOSITORY** -
|
387
|
+
The repository from which you are deploying the code. This is set
|
368
388
|
automatically if you are using capistrano.
|
369
389
|
|
370
|
-
- **BUGSNAG_BRANCH** -
|
390
|
+
- **BUGSNAG_BRANCH** -
|
371
391
|
The source control branch from which you are deploying the code.
|
372
392
|
This is set automatically if you are using capistrano.
|
373
393
|
|
374
|
-
- **BUGSNAG_REVISION** -
|
394
|
+
- **BUGSNAG_REVISION** -
|
375
395
|
The source control revision for the code you are currently deploying.
|
376
396
|
This is set automatically if you are using capistrano.
|
377
397
|
|
@@ -385,8 +405,8 @@ documentation.
|
|
385
405
|
|
386
406
|
### EventMachine Apps
|
387
407
|
|
388
|
-
If your app uses [EventMachine](http://rubyeventmachine.com/) you'll need to
|
389
|
-
manually notify Bugsnag of errors. There are two ways to do this in your
|
408
|
+
If your app uses [EventMachine](http://rubyeventmachine.com/) you'll need to
|
409
|
+
manually notify Bugsnag of errors. There are two ways to do this in your
|
390
410
|
EventMachine apps, first you should implement `EventMachine.error_handler`:
|
391
411
|
|
392
412
|
```ruby
|
@@ -438,5 +458,5 @@ Build Status
|
|
438
458
|
License
|
439
459
|
-------
|
440
460
|
|
441
|
-
The Bugsnag ruby notifier is free software released under the MIT License.
|
442
|
-
See [LICENSE.txt](https://github.com/bugsnag/bugsnag-ruby/blob/master/LICENSE.txt) for details.
|
461
|
+
The Bugsnag ruby notifier is free software released under the MIT License.
|
462
|
+
See [LICENSE.txt](https://github.com/bugsnag/bugsnag-ruby/blob/master/LICENSE.txt) for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.18
|
data/bugsnag.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bugsnag}
|
8
|
-
s.version = "1.2.
|
8
|
+
s.version = "1.2.18"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Smith"]
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
|
|
33
33
|
"lib/bugsnag/configuration.rb",
|
34
34
|
"lib/bugsnag/delay/resque.rb",
|
35
35
|
"lib/bugsnag/helpers.rb",
|
36
|
+
"lib/bugsnag/meta_data.rb",
|
36
37
|
"lib/bugsnag/middleware/callbacks.rb",
|
37
38
|
"lib/bugsnag/middleware/rack_request.rb",
|
38
39
|
"lib/bugsnag/middleware/rails2_request.rb",
|
data/lib/bugsnag.rb
CHANGED
@@ -2,6 +2,7 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
require "bugsnag/version"
|
4
4
|
require "bugsnag/configuration"
|
5
|
+
require "bugsnag/meta_data"
|
5
6
|
require "bugsnag/notification"
|
6
7
|
require "bugsnag/helpers"
|
7
8
|
|
@@ -30,7 +31,7 @@ module Bugsnag
|
|
30
31
|
|
31
32
|
# Log that we are ready to rock
|
32
33
|
if configuration.api_key && !@logged_ready
|
33
|
-
log "Bugsnag exception handler #{VERSION} ready, api_key=#{configuration.api_key}"
|
34
|
+
log "Bugsnag exception handler #{VERSION} ready, api_key=#{configuration.api_key}"
|
34
35
|
@logged_ready = true
|
35
36
|
end
|
36
37
|
end
|
@@ -46,7 +47,7 @@ module Bugsnag
|
|
46
47
|
notification.deliver unless notification.ignore?
|
47
48
|
end
|
48
49
|
|
49
|
-
# Auto notify of an exception, called from rails and rack exception
|
50
|
+
# Auto notify of an exception, called from rails and rack exception
|
50
51
|
# rescuers, unless auto notification is disabled, or we should ignore this
|
51
52
|
# error class
|
52
53
|
def auto_notify(exception, overrides=nil, request_data=nil)
|
@@ -78,7 +79,7 @@ module Bugsnag
|
|
78
79
|
Bugsnag.configuration.set_request_data(key, value)
|
79
80
|
end
|
80
81
|
|
81
|
-
# Clear all "per-request" data, temporal data for use in bugsnag middleware
|
82
|
+
# Clear all "per-request" data, temporal data for use in bugsnag middleware
|
82
83
|
# This method should be called after each distinct request or session ends
|
83
84
|
# Eg. After completing a page request in a web app
|
84
85
|
def clear_request_data
|
@@ -95,4 +96,4 @@ module Bugsnag
|
|
95
96
|
Bugsnag.configuration.request_data[:after_callbacks] ||= []
|
96
97
|
end
|
97
98
|
end
|
98
|
-
end
|
99
|
+
end
|
data/lib/bugsnag/notification.rb
CHANGED
@@ -17,16 +17,16 @@ module Bugsnag
|
|
17
17
|
# HTTParty settings
|
18
18
|
headers "Content-Type" => "application/json"
|
19
19
|
default_timeout 5
|
20
|
-
|
20
|
+
|
21
21
|
attr_accessor :context
|
22
22
|
attr_accessor :user_id
|
23
|
-
|
23
|
+
|
24
24
|
class << self
|
25
25
|
def deliver_exception_payload(endpoint, payload)
|
26
26
|
begin
|
27
27
|
payload_string = Bugsnag::Helpers.dump_json(payload)
|
28
|
-
|
29
|
-
# If the payload is going to be too long, we trim the hashes to send
|
28
|
+
|
29
|
+
# If the payload is going to be too long, we trim the hashes to send
|
30
30
|
# a minimal payload instead
|
31
31
|
if payload_string.length > 128000
|
32
32
|
payload[:events].each {|e| e[:metaData] = Bugsnag::Helpers.reduce_hash_size(e[:metaData])}
|
@@ -50,7 +50,7 @@ module Bugsnag
|
|
50
50
|
@overrides = Bugsnag::Helpers.flatten_meta_data(overrides) || {}
|
51
51
|
@request_data = request_data
|
52
52
|
@meta_data = {}
|
53
|
-
|
53
|
+
|
54
54
|
# Unwrap exceptions
|
55
55
|
@exceptions = []
|
56
56
|
ex = exception
|
@@ -66,7 +66,7 @@ module Bugsnag
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
# Add a single value as custom data, to this notification
|
71
71
|
def add_custom_data(name, value)
|
72
72
|
@meta_data[:custom] ||= {}
|
@@ -110,13 +110,24 @@ module Bugsnag
|
|
110
110
|
Bugsnag.warn "You should set your app's release_stage (see https://bugsnag.com/docs/notifiers/ruby#release_stage)." unless @configuration.release_stage
|
111
111
|
|
112
112
|
@meta_data = {}
|
113
|
-
|
113
|
+
|
114
114
|
# Run the middleware here, at the end of the middleware stack, execute the actual delivery
|
115
115
|
@configuration.middleware.run(self) do
|
116
116
|
# Now override the required fields
|
117
|
+
exceptions.each do |exception|
|
118
|
+
if exception.class.include?(Bugsnag::MetaData)
|
119
|
+
if exception.bugsnag_user_id.is_a?(String)
|
120
|
+
self.user_id = exception.bugsnag_user_id
|
121
|
+
end
|
122
|
+
if exception.bugsnag_context.is_a?(String)
|
123
|
+
self.context = exception.bugsnag_context
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
117
128
|
[:user_id, :context].each do |symbol|
|
118
129
|
if @overrides[symbol]
|
119
|
-
self.send("#{symbol}=", @overrides[symbol]
|
130
|
+
self.send("#{symbol}=", @overrides[symbol])
|
120
131
|
@overrides.delete symbol
|
121
132
|
end
|
122
133
|
end
|
@@ -132,7 +143,7 @@ module Bugsnag
|
|
132
143
|
:context => self.context,
|
133
144
|
:userId => self.user_id,
|
134
145
|
:exceptions => exception_list,
|
135
|
-
:metaData => Bugsnag::Helpers.cleanup_obj(generate_meta_data(@overrides), @configuration.params_filters)
|
146
|
+
:metaData => Bugsnag::Helpers.cleanup_obj(generate_meta_data(@exceptions, @overrides), @configuration.params_filters)
|
136
147
|
}.reject {|k,v| v.nil? }
|
137
148
|
|
138
149
|
# Build the payload hash
|
@@ -160,39 +171,52 @@ module Bugsnag
|
|
160
171
|
def request_data
|
161
172
|
@request_data || Bugsnag.configuration.request_data
|
162
173
|
end
|
163
|
-
|
174
|
+
|
164
175
|
def exceptions
|
165
176
|
@exceptions
|
166
177
|
end
|
167
178
|
|
168
179
|
private
|
169
|
-
|
170
|
-
|
180
|
+
|
181
|
+
# Generate the meta data from both the request configuration, the overrides and the exceptions for this notification
|
182
|
+
def generate_meta_data(exceptions, overrides)
|
171
183
|
# Copy the request meta data so we dont edit it by mistake
|
172
184
|
meta_data = @meta_data.dup
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
if meta_data[key]
|
180
|
-
# If its a clash, merge with the existing data
|
181
|
-
meta_data[key].merge! value
|
182
|
-
else
|
183
|
-
# Add it as is if its not special
|
184
|
-
meta_data[key] = value
|
185
|
+
|
186
|
+
exceptions.each do |exception|
|
187
|
+
if exception.class.include?(Bugsnag::MetaData) && exception.bugsnag_meta_data
|
188
|
+
exception.bugsnag_meta_data.each do |key, value|
|
189
|
+
add_to_meta_data key, value, meta_data
|
185
190
|
end
|
186
|
-
else
|
187
|
-
meta_data[:custom] ||= {}
|
188
|
-
meta_data[:custom][key] = value
|
189
191
|
end
|
190
192
|
end
|
191
|
-
|
193
|
+
|
194
|
+
overrides.each do |key, value|
|
195
|
+
add_to_meta_data key, value, meta_data
|
196
|
+
end
|
197
|
+
|
192
198
|
meta_data
|
193
199
|
end
|
194
|
-
|
195
|
-
def
|
200
|
+
|
201
|
+
def add_to_meta_data(key, value, meta_data)
|
202
|
+
# If its a hash, its a tab so we can just add it providing its not reserved
|
203
|
+
if value.is_a? Hash
|
204
|
+
key = key.to_sym
|
205
|
+
|
206
|
+
if meta_data[key]
|
207
|
+
# If its a clash, merge with the existing data
|
208
|
+
meta_data[key].merge! value
|
209
|
+
else
|
210
|
+
# Add it as is if its not special
|
211
|
+
meta_data[key] = value
|
212
|
+
end
|
213
|
+
else
|
214
|
+
meta_data[:custom] ||= {}
|
215
|
+
meta_data[:custom][key] = value
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def exception_list
|
196
220
|
@exceptions.map do |exception|
|
197
221
|
{
|
198
222
|
:errorClass => error_class(exception),
|
@@ -201,15 +225,15 @@ module Bugsnag
|
|
201
225
|
}
|
202
226
|
end
|
203
227
|
end
|
204
|
-
|
228
|
+
|
205
229
|
def error_class(exception)
|
206
|
-
# The "Class" check is for some strange exceptions like Timeout::Error
|
230
|
+
# The "Class" check is for some strange exceptions like Timeout::Error
|
207
231
|
# which throw the error class instead of an instance
|
208
232
|
(exception.is_a? Class) ? exception.name : exception.class.name
|
209
233
|
end
|
210
234
|
|
211
235
|
def stacktrace(exception)
|
212
|
-
(exception.backtrace || caller).map do |trace|
|
236
|
+
(exception.backtrace || caller).map do |trace|
|
213
237
|
method = nil
|
214
238
|
file, line_str, method_str = trace.split(":")
|
215
239
|
|
@@ -224,7 +248,7 @@ module Bugsnag
|
|
224
248
|
trace_hash[:lineNumber] = line_str.to_i
|
225
249
|
|
226
250
|
# Clean up the file path in the stacktrace
|
227
|
-
if defined?(Bugsnag.configuration.project_root) && Bugsnag.configuration.project_root.to_s != ''
|
251
|
+
if defined?(Bugsnag.configuration.project_root) && Bugsnag.configuration.project_root.to_s != ''
|
228
252
|
file.sub!(/#{Bugsnag.configuration.project_root}\//, "")
|
229
253
|
end
|
230
254
|
|
@@ -250,4 +274,4 @@ module Bugsnag
|
|
250
274
|
end.compact
|
251
275
|
end
|
252
276
|
end
|
253
|
-
end
|
277
|
+
end
|
data/spec/notification_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'securerandom'
|
|
3
3
|
|
4
4
|
module ActiveRecord; class RecordNotFound < RuntimeError; end; end
|
5
5
|
class NestedException < StandardError; attr_accessor :original_exception; end
|
6
|
+
class BugsnagTestExceptionWithMetaData < Exception; include Bugsnag::MetaData; end
|
6
7
|
|
7
8
|
describe Bugsnag::Notification do
|
8
9
|
it "should contain an api_key if one is set" do
|
@@ -86,6 +87,92 @@ describe Bugsnag::Notification do
|
|
86
87
|
})
|
87
88
|
end
|
88
89
|
|
90
|
+
it "should accept meta data from an exception that mixes in Bugsnag::MetaData" do
|
91
|
+
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
|
92
|
+
event = get_event_from_payload(payload)
|
93
|
+
event[:metaData][:some_tab].should_not be_nil
|
94
|
+
event[:metaData][:some_tab][:info].should be == "here"
|
95
|
+
event[:metaData][:some_tab][:data].should be == "also here"
|
96
|
+
end
|
97
|
+
|
98
|
+
exception = BugsnagTestExceptionWithMetaData.new("It crashed")
|
99
|
+
exception.bugsnag_meta_data = {
|
100
|
+
:some_tab => {
|
101
|
+
:info => "here",
|
102
|
+
:data => "also here"
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
Bugsnag.notify(exception)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should accept meta data from an exception that mixes in Bugsnag::MetaData, but override using the overrides" do
|
110
|
+
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
|
111
|
+
event = get_event_from_payload(payload)
|
112
|
+
event[:metaData][:some_tab].should_not be_nil
|
113
|
+
event[:metaData][:some_tab][:info].should be == "overridden"
|
114
|
+
event[:metaData][:some_tab][:data].should be == "also here"
|
115
|
+
end
|
116
|
+
|
117
|
+
exception = BugsnagTestExceptionWithMetaData.new("It crashed")
|
118
|
+
exception.bugsnag_meta_data = {
|
119
|
+
:some_tab => {
|
120
|
+
:info => "here",
|
121
|
+
:data => "also here"
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
Bugsnag.notify(exception, {:some_tab => {:info => "overridden"}})
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should accept user_id from an exception that mixes in Bugsnag::MetaData" do
|
129
|
+
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
|
130
|
+
event = get_event_from_payload(payload)
|
131
|
+
event[:userId].should be == "exception_user_id"
|
132
|
+
end
|
133
|
+
|
134
|
+
exception = BugsnagTestExceptionWithMetaData.new("It crashed")
|
135
|
+
exception.bugsnag_user_id = "exception_user_id"
|
136
|
+
|
137
|
+
Bugsnag.notify(exception)
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should accept user_id from an exception that mixes in Bugsnag::MetaData, but override using the overrides" do
|
141
|
+
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
|
142
|
+
event = get_event_from_payload(payload)
|
143
|
+
event[:userId].should be == "override_user_id"
|
144
|
+
end
|
145
|
+
|
146
|
+
exception = BugsnagTestExceptionWithMetaData.new("It crashed")
|
147
|
+
exception.bugsnag_user_id = "exception_user_id"
|
148
|
+
|
149
|
+
Bugsnag.notify(exception, {:user_id => "override_user_id"})
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should accept context from an exception that mixes in Bugsnag::MetaData" do
|
153
|
+
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
|
154
|
+
event = get_event_from_payload(payload)
|
155
|
+
event[:context].should be == "exception_context"
|
156
|
+
end
|
157
|
+
|
158
|
+
exception = BugsnagTestExceptionWithMetaData.new("It crashed")
|
159
|
+
exception.bugsnag_context = "exception_context"
|
160
|
+
|
161
|
+
Bugsnag.notify(exception)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should accept context from an exception that mixes in Bugsnag::MetaData, but override using the overrides" do
|
165
|
+
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
|
166
|
+
event = get_event_from_payload(payload)
|
167
|
+
event[:context].should be == "override_context"
|
168
|
+
end
|
169
|
+
|
170
|
+
exception = BugsnagTestExceptionWithMetaData.new("It crashed")
|
171
|
+
exception.bugsnag_context = "exception_context"
|
172
|
+
|
173
|
+
Bugsnag.notify(exception, {:context => "override_context"})
|
174
|
+
end
|
175
|
+
|
89
176
|
it "should accept meta_data in overrides (for backwards compatibility) and merge it into metaData" do
|
90
177
|
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
|
91
178
|
event = get_event_from_payload(payload)
|
@@ -311,7 +398,7 @@ describe Bugsnag::Notification do
|
|
311
398
|
|
312
399
|
Bugsnag.notify_or_ignore(ex)
|
313
400
|
end
|
314
|
-
|
401
|
+
|
315
402
|
it "should not unwrap more than 5 exceptions" do
|
316
403
|
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
|
317
404
|
event = get_event_from_payload(payload)
|
@@ -325,4 +412,4 @@ describe Bugsnag::Notification do
|
|
325
412
|
|
326
413
|
Bugsnag.notify_or_ignore(first_ex)
|
327
414
|
end
|
328
|
-
end
|
415
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 1.2.
|
8
|
+
- 18
|
9
|
+
version: 1.2.18
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- James Smith
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/bugsnag/configuration.rb
|
117
117
|
- lib/bugsnag/delay/resque.rb
|
118
118
|
- lib/bugsnag/helpers.rb
|
119
|
+
- lib/bugsnag/meta_data.rb
|
119
120
|
- lib/bugsnag/middleware/callbacks.rb
|
120
121
|
- lib/bugsnag/middleware/rack_request.rb
|
121
122
|
- lib/bugsnag/middleware/rails2_request.rb
|