bugsnag 4.2.1 → 6.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.yardopts +12 -0
- data/CHANGELOG.md +814 -0
- data/README.md +21 -25
- data/VERSION +1 -1
- data/bugsnag.gemspec +19 -8
- data/lib/bugsnag/breadcrumb_type.rb +14 -0
- data/lib/bugsnag/breadcrumbs/breadcrumb.rb +109 -0
- data/lib/bugsnag/breadcrumbs/breadcrumbs.rb +13 -0
- data/lib/bugsnag/breadcrumbs/on_breadcrumb_callback_list.rb +48 -0
- data/lib/bugsnag/breadcrumbs/validator.rb +29 -0
- data/lib/bugsnag/cleaner.rb +170 -59
- data/lib/bugsnag/code_extractor.rb +137 -0
- data/lib/bugsnag/configuration.rb +670 -45
- data/lib/bugsnag/delivery/synchronous.rb +31 -14
- data/lib/bugsnag/delivery/thread_queue.rb +23 -6
- data/lib/bugsnag/delivery.rb +13 -0
- data/lib/bugsnag/endpoint_configuration.rb +11 -0
- data/lib/bugsnag/endpoint_validator.rb +80 -0
- data/lib/bugsnag/error.rb +25 -0
- data/lib/bugsnag/event.rb +5 -0
- data/lib/bugsnag/feature_flag.rb +74 -0
- data/lib/bugsnag/helpers.rb +121 -25
- data/lib/bugsnag/integrations/delayed_job.rb +51 -0
- data/lib/bugsnag/integrations/mailman.rb +43 -0
- data/lib/bugsnag/integrations/mongo.rb +133 -0
- data/lib/bugsnag/integrations/que.rb +53 -0
- data/lib/bugsnag/integrations/rack.rb +83 -0
- data/lib/bugsnag/integrations/rails/active_job.rb +100 -0
- data/lib/bugsnag/{rails → integrations/rails}/active_record_rescue.rb +10 -1
- data/lib/bugsnag/{rails → integrations/rails}/controller_methods.rb +1 -9
- data/lib/bugsnag/integrations/rails/rails_breadcrumbs.rb +115 -0
- data/lib/bugsnag/integrations/railtie.rb +153 -0
- data/lib/bugsnag/integrations/rake.rb +74 -0
- data/lib/bugsnag/integrations/resque.rb +94 -0
- data/lib/bugsnag/integrations/shoryuken.rb +50 -0
- data/lib/bugsnag/integrations/sidekiq.rb +68 -0
- data/lib/bugsnag/meta_data.rb +1 -0
- data/lib/bugsnag/middleware/active_job.rb +18 -0
- data/lib/bugsnag/middleware/breadcrumbs.rb +21 -0
- data/lib/bugsnag/middleware/callbacks.rb +6 -8
- data/lib/bugsnag/middleware/classify_error.rb +50 -0
- data/lib/bugsnag/middleware/clearance_user.rb +33 -0
- data/lib/bugsnag/middleware/delayed_job.rb +93 -0
- data/lib/bugsnag/middleware/discard_error_class.rb +30 -0
- data/lib/bugsnag/middleware/exception_meta_data.rb +42 -0
- data/lib/bugsnag/middleware/ignore_error_class.rb +26 -0
- data/lib/bugsnag/middleware/mailman.rb +6 -4
- data/lib/bugsnag/middleware/rack_request.rb +126 -30
- data/lib/bugsnag/middleware/rails3_request.rb +15 -17
- data/lib/bugsnag/middleware/rake.rb +7 -5
- data/lib/bugsnag/middleware/session_data.rb +25 -0
- data/lib/bugsnag/middleware/sidekiq.rb +9 -4
- data/lib/bugsnag/middleware/suggestion_data.rb +34 -0
- data/lib/bugsnag/middleware/warden_user.rb +11 -6
- data/lib/bugsnag/middleware_stack.rb +62 -9
- data/lib/bugsnag/on_error_callbacks.rb +33 -0
- data/lib/bugsnag/report.rb +516 -0
- data/lib/bugsnag/session_tracker.rb +182 -0
- data/lib/bugsnag/stacktrace.rb +82 -0
- data/lib/bugsnag/tasks/bugsnag.rake +2 -70
- data/lib/bugsnag/utility/circular_buffer.rb +62 -0
- data/lib/bugsnag/utility/duplicator.rb +124 -0
- data/lib/bugsnag/utility/feature_data_store.rb +41 -0
- data/lib/bugsnag/utility/feature_flag_delegate.rb +89 -0
- data/lib/bugsnag/utility/metadata_delegate.rb +102 -0
- data/lib/bugsnag.rb +528 -80
- metadata +61 -123
- data/.document +0 -5
- data/.gitignore +0 -52
- data/.rspec +0 -3
- data/.travis.yml +0 -14
- data/CONTRIBUTING.md +0 -47
- data/Gemfile +0 -2
- data/Rakefile +0 -29
- data/lib/bugsnag/capistrano.rb +0 -7
- data/lib/bugsnag/capistrano2.rb +0 -32
- data/lib/bugsnag/delay/resque.rb +0 -21
- data/lib/bugsnag/delayed_job.rb +0 -57
- data/lib/bugsnag/deploy.rb +0 -34
- data/lib/bugsnag/mailman.rb +0 -28
- data/lib/bugsnag/middleware/rails2_request.rb +0 -52
- data/lib/bugsnag/notification.rb +0 -459
- data/lib/bugsnag/rack.rb +0 -53
- data/lib/bugsnag/rails/action_controller_rescue.rb +0 -62
- data/lib/bugsnag/rails.rb +0 -66
- data/lib/bugsnag/railtie.rb +0 -80
- data/lib/bugsnag/rake.rb +0 -25
- data/lib/bugsnag/resque.rb +0 -40
- data/lib/bugsnag/sidekiq.rb +0 -42
- data/lib/bugsnag/tasks/bugsnag.cap +0 -48
- data/rails/init.rb +0 -7
- data/spec/cleaner_spec.rb +0 -138
- data/spec/code_spec.rb +0 -86
- data/spec/fixtures/crashes/end_of_file.rb +0 -9
- data/spec/fixtures/crashes/short_file.rb +0 -1
- data/spec/fixtures/crashes/start_of_file.rb +0 -9
- data/spec/fixtures/middleware/internal_info_setter.rb +0 -11
- data/spec/fixtures/middleware/public_info_setter.rb +0 -11
- data/spec/fixtures/tasks/Rakefile +0 -15
- data/spec/helper_spec.rb +0 -163
- data/spec/integration_spec.rb +0 -132
- data/spec/middleware_spec.rb +0 -181
- data/spec/notification_spec.rb +0 -877
- data/spec/rack_spec.rb +0 -56
- data/spec/spec_helper.rb +0 -53
data/spec/helper_spec.rb
DELETED
@@ -1,163 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
require 'set'
|
5
|
-
|
6
|
-
describe Bugsnag::Helpers do
|
7
|
-
|
8
|
-
describe "trim_if_needed" do
|
9
|
-
|
10
|
-
it "breaks recursion" do
|
11
|
-
a = [1, 2, 3]
|
12
|
-
b = [2, a]
|
13
|
-
a << b
|
14
|
-
value = Bugsnag::Helpers.trim_if_needed(a)
|
15
|
-
expect(value).to eq([1, 2, 3, [2, "[RECURSION]"]])
|
16
|
-
end
|
17
|
-
|
18
|
-
it "does not break equal objects without recursion" do
|
19
|
-
data = [1, [1, 2], [1, 2], "a"]
|
20
|
-
value = Bugsnag::Helpers.trim_if_needed(data)
|
21
|
-
expect(value).to eq data
|
22
|
-
end
|
23
|
-
|
24
|
-
it "preserves bool types" do
|
25
|
-
value = Bugsnag::Helpers.trim_if_needed([1, 3, true, "NO", "2", false])
|
26
|
-
expect(value[2]).to be_a(TrueClass)
|
27
|
-
expect(value[5]).to be_a(FalseClass)
|
28
|
-
end
|
29
|
-
|
30
|
-
it "preserves Numeric types" do
|
31
|
-
value = Bugsnag::Helpers.trim_if_needed([1, 3.445, true, "NO", "2", false])
|
32
|
-
expect(value[0]).to be_a(Numeric)
|
33
|
-
expect(value[1]).to be_a(Numeric)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "preserves String types" do
|
37
|
-
value = Bugsnag::Helpers.trim_if_needed([1, 3, true, "NO", "2", false])
|
38
|
-
expect(value[3]).to be_a(String)
|
39
|
-
expect(value[4]).to be_a(String)
|
40
|
-
end
|
41
|
-
|
42
|
-
context "payload length is less than allowed" do
|
43
|
-
|
44
|
-
it "does not change strings" do
|
45
|
-
value = SecureRandom.hex(4096)
|
46
|
-
expect(Bugsnag::Helpers.trim_if_needed(value)).to eq value
|
47
|
-
end
|
48
|
-
|
49
|
-
it "does not change arrays" do
|
50
|
-
value = 1000.times.map {|i| "#{i} - #{i + 1}" }
|
51
|
-
expect(Bugsnag::Helpers.trim_if_needed(value)).to eq value
|
52
|
-
end
|
53
|
-
|
54
|
-
it "does not change hashes" do
|
55
|
-
value = Hash[*1000.times.map{|i| ["#{i}", i]}.flatten]
|
56
|
-
expect(Bugsnag::Helpers.trim_if_needed(value)).to eq value
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "payload length is greater than allowed" do
|
61
|
-
|
62
|
-
context "value is a String" do
|
63
|
-
it "trims length" do
|
64
|
-
value = Bugsnag::Helpers.trim_if_needed(SecureRandom.hex(500_000/2))
|
65
|
-
expect(::JSON.dump(value.length).length).to be < Bugsnag::Helpers::MAX_STRING_LENGTH
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "value is an Array" do
|
70
|
-
it "trims nested string contents" do
|
71
|
-
value = [[30.times.map {|i| SecureRandom.hex(8192) }]]
|
72
|
-
json = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(value))
|
73
|
-
expect(json.length).to be < Bugsnag::Helpers::MAX_PAYLOAD_LENGTH
|
74
|
-
end
|
75
|
-
|
76
|
-
it "trims string contents" do
|
77
|
-
value = 30.times.map {|i| SecureRandom.hex(8192) }
|
78
|
-
json = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(value))
|
79
|
-
expect(json.length).to be < Bugsnag::Helpers::MAX_PAYLOAD_LENGTH
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "value is a Set" do
|
84
|
-
it "trims string contents" do
|
85
|
-
value = Set.new(30.times.map {|i| SecureRandom.hex(8192) })
|
86
|
-
json = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(value))
|
87
|
-
expect(json.length).to be < Bugsnag::Helpers::MAX_PAYLOAD_LENGTH
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
context "value can be converted to a String" do
|
92
|
-
it "converts to a string and trims" do
|
93
|
-
value = Set.new(30_000.times.map {|i| Bugsnag::Helpers })
|
94
|
-
json = ::JSON.dump(Bugsnag::Helpers.trim_if_needed(value))
|
95
|
-
expect(json.length).to be < Bugsnag::Helpers::MAX_PAYLOAD_LENGTH
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
context "value is a Hash" do
|
100
|
-
|
101
|
-
before(:each) do
|
102
|
-
@metadata = {
|
103
|
-
:short_string => "this should not be truncated",
|
104
|
-
:long_string => 10000.times.map {|i| "should truncate" }.join(""),
|
105
|
-
:long_string_ary => 30.times.map {|i| SecureRandom.hex(8192) }
|
106
|
-
}
|
107
|
-
|
108
|
-
@trimmed_metadata = Bugsnag::Helpers.trim_if_needed @metadata
|
109
|
-
end
|
110
|
-
|
111
|
-
it "does not trim short values" do
|
112
|
-
expect(@trimmed_metadata[:short_string]).to eq @metadata[:short_string]
|
113
|
-
end
|
114
|
-
|
115
|
-
it "trims long string values" do
|
116
|
-
expect(@trimmed_metadata[:long_string].length).to eq(Bugsnag::Helpers::MAX_STRING_LENGTH)
|
117
|
-
expect(@trimmed_metadata[:long_string].match(/\[TRUNCATED\]$/)).to_not be_nil
|
118
|
-
end
|
119
|
-
|
120
|
-
it "trims nested long string values" do
|
121
|
-
@trimmed_metadata[:long_string_ary].each do |str|
|
122
|
-
expect(str.match(/\[TRUNCATED\]$/)).to_not be_nil
|
123
|
-
expect(str.length).to eq(Bugsnag::Helpers::MAX_STRING_LENGTH)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
it "does not change the argument value" do
|
128
|
-
expect(@metadata[:long_string].length).to be > Bugsnag::Helpers::MAX_STRING_LENGTH
|
129
|
-
expect(@metadata[:long_string].match(/\[TRUNCATED\]$/)).to be_nil
|
130
|
-
expect(@metadata[:short_string].length).to eq(28)
|
131
|
-
expect(@metadata[:short_string]).to eq("this should not be truncated")
|
132
|
-
expect(@trimmed_metadata[:long_string_ary].length).to eq(30)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "and trimmed strings are not enough" do
|
137
|
-
it "truncates long arrays" do
|
138
|
-
value = [100.times.map {|i| SecureRandom.hex(8192) }, "a"]
|
139
|
-
trimmed_value = Bugsnag::Helpers.trim_if_needed(value)
|
140
|
-
expect(trimmed_value.length).to eq 2
|
141
|
-
expect(trimmed_value.first.length).to eq Bugsnag::Helpers::MAX_ARRAY_LENGTH
|
142
|
-
trimmed_value.first.each do |str|
|
143
|
-
expect(str.match(/\[TRUNCATED\]$/)).to_not be_nil
|
144
|
-
expect(str.length).to eq(Bugsnag::Helpers::MAX_STRING_LENGTH)
|
145
|
-
end
|
146
|
-
|
147
|
-
expect(::JSON.dump(trimmed_value).length).to be < Bugsnag::Helpers::MAX_PAYLOAD_LENGTH
|
148
|
-
end
|
149
|
-
|
150
|
-
it "removes metadata from events" do
|
151
|
-
metadata = Hash[*20000.times.map {|i| [i,i+1]}.flatten]
|
152
|
-
frames = 100.times.map {|i| SecureRandom.hex(4096) }
|
153
|
-
value = {key:"abc", events:[{metaData: metadata, frames: frames, cake: "carrot"}]}
|
154
|
-
trimmed_value = Bugsnag::Helpers.trim_if_needed(value)
|
155
|
-
expect(::JSON.dump(trimmed_value).length).to be < Bugsnag::Helpers::MAX_PAYLOAD_LENGTH
|
156
|
-
expect(trimmed_value[:key]).to eq value[:key]
|
157
|
-
expect(trimmed_value[:events].first.keys.to_set).to eq [:frames, :cake].to_set
|
158
|
-
expect(trimmed_value[:events].first[:metaData]).to be_nil
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
data/spec/integration_spec.rb
DELETED
@@ -1,132 +0,0 @@
|
|
1
|
-
require 'webrick'
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
describe 'Bugsnag' do
|
6
|
-
server = nil
|
7
|
-
queue = Queue.new
|
8
|
-
|
9
|
-
before do
|
10
|
-
server = WEBrick::HTTPServer.new :Port => 0, :Logger => WEBrick::Log.new("/dev/null"), :AccessLog => []
|
11
|
-
server.mount_proc '/' do |req, res|
|
12
|
-
queue.push req.body
|
13
|
-
res.status = 200
|
14
|
-
res.body = "OK\n"
|
15
|
-
end
|
16
|
-
Thread.new{ server.start }
|
17
|
-
end
|
18
|
-
after do
|
19
|
-
server.stop
|
20
|
-
queue.clear
|
21
|
-
end
|
22
|
-
|
23
|
-
let(:request) { JSON.parse(queue.pop) }
|
24
|
-
|
25
|
-
it 'should run the rake middleware when rake tasks crash' do
|
26
|
-
ENV['BUGSNAG_TEST_SERVER_PORT'] = server.config[:Port].to_s
|
27
|
-
task_fixtures_path = File.join(File.dirname(__FILE__), 'fixtures', 'tasks')
|
28
|
-
Dir.chdir(task_fixtures_path) do
|
29
|
-
system("bundle exec rake test:crash > /dev/null 2>&1")
|
30
|
-
end
|
31
|
-
expect(request["events"][0]["metaData"]["rake_task"]).not_to be_nil
|
32
|
-
expect(request["events"][0]["metaData"]["rake_task"]["name"]).to eq("test:crash")
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should send notifications over the wire' do
|
36
|
-
Bugsnag.configure do |config|
|
37
|
-
config.endpoint = "localhost:#{server.config[:Port]}"
|
38
|
-
config.use_ssl = false
|
39
|
-
end
|
40
|
-
WebMock.allow_net_connect!
|
41
|
-
|
42
|
-
Bugsnag.notify 'yo'
|
43
|
-
|
44
|
-
expect(request['events'][0]['exceptions'][0]['message']).to eq('yo')
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'should send deploys over the wire' do
|
48
|
-
Bugsnag.configure do |config|
|
49
|
-
config.endpoint = "localhost:#{server.config[:Port]}"
|
50
|
-
config.use_ssl = false
|
51
|
-
end
|
52
|
-
WebMock.allow_net_connect!
|
53
|
-
|
54
|
-
Bugsnag::Deploy.notify :app_version => '1.1.1'
|
55
|
-
|
56
|
-
expect(request['appVersion']).to eq('1.1.1')
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'should work with threadpool delivery' do
|
60
|
-
Bugsnag.configure do |config|
|
61
|
-
config.endpoint = "localhost:#{server.config[:Port]}"
|
62
|
-
config.use_ssl = false
|
63
|
-
config.delivery_method = :thread_queue
|
64
|
-
end
|
65
|
-
WebMock.allow_net_connect!
|
66
|
-
|
67
|
-
Bugsnag.notify 'yo'
|
68
|
-
|
69
|
-
expect(request['events'][0]['exceptions'][0]['message']).to eq('yo')
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should work with threadpool delivery after fork' do
|
73
|
-
is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
74
|
-
unless is_jruby #jruby doesn't support fork, so this test doesn't apply
|
75
|
-
Bugsnag.configure do |config|
|
76
|
-
config.endpoint = "localhost:#{server.config[:Port]}"
|
77
|
-
config.use_ssl = false
|
78
|
-
config.delivery_method = :thread_queue
|
79
|
-
end
|
80
|
-
WebMock.allow_net_connect!
|
81
|
-
|
82
|
-
Bugsnag.notify 'yo'
|
83
|
-
|
84
|
-
Process.fork do
|
85
|
-
Bugsnag.notify 'yo too'
|
86
|
-
end
|
87
|
-
Process.wait
|
88
|
-
|
89
|
-
expect(queue.length).to eq(2)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe 'with a proxy' do
|
94
|
-
proxy = nil
|
95
|
-
pqueue = Queue.new
|
96
|
-
|
97
|
-
before do
|
98
|
-
proxy = WEBrick::HTTPServer.new :Port => 0, :Logger => WEBrick::Log.new("/dev/null"), :AccessLog => []
|
99
|
-
proxy.mount_proc '/' do |req, res|
|
100
|
-
pqueue.push req
|
101
|
-
res.status = 200
|
102
|
-
res.body = "OK\n"
|
103
|
-
end
|
104
|
-
Thread.new{ proxy.start }
|
105
|
-
end
|
106
|
-
after do
|
107
|
-
proxy.stop
|
108
|
-
end
|
109
|
-
|
110
|
-
let(:proxied_request) { pqueue.pop }
|
111
|
-
|
112
|
-
it 'should use a proxy when configured' do
|
113
|
-
Bugsnag.configure do |config|
|
114
|
-
|
115
|
-
config.endpoint = "localhost:#{server.config[:Port]}"
|
116
|
-
config.use_ssl = false
|
117
|
-
|
118
|
-
config.proxy_host = 'localhost'
|
119
|
-
config.proxy_port = proxy.config[:Port]
|
120
|
-
config.proxy_user = 'conrad'
|
121
|
-
config.proxy_password = '$ecret'
|
122
|
-
end
|
123
|
-
|
124
|
-
Bugsnag.notify 'oy'
|
125
|
-
|
126
|
-
r = proxied_request
|
127
|
-
|
128
|
-
expect(r.header['proxy-authorization'].first).to eq("Basic Y29ucmFkOiRlY3JldA==")
|
129
|
-
expect(r.request_line).to eq("POST http://localhost:#{server.config[:Port]}/ HTTP/1.1\r\n")
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
data/spec/middleware_spec.rb
DELETED
@@ -1,181 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'fixtures/middleware/public_info_setter'
|
3
|
-
require 'fixtures/middleware/internal_info_setter'
|
4
|
-
|
5
|
-
describe Bugsnag::MiddlewareStack do
|
6
|
-
it "runs before_bugsnag_notify callbacks, adding a tab" do
|
7
|
-
callback_run_count = 0
|
8
|
-
Bugsnag.before_notify_callbacks << lambda {|notif|
|
9
|
-
notif.add_tab(:some_tab, {
|
10
|
-
:info => "here",
|
11
|
-
:data => "also here"
|
12
|
-
})
|
13
|
-
callback_run_count += 1
|
14
|
-
}
|
15
|
-
|
16
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
17
|
-
expect(callback_run_count).to eq(1)
|
18
|
-
|
19
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
20
|
-
event = get_event_from_payload(payload)
|
21
|
-
expect(event["metaData"]["some_tab"]).not_to be_nil
|
22
|
-
expect(event["metaData"]["some_tab"]["info"]).to eq("here")
|
23
|
-
expect(event["metaData"]["some_tab"]["data"]).to eq("also here")
|
24
|
-
}
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
it "runs before_bugsnag_notify callbacks, adding custom data" do
|
29
|
-
callback_run_count = 0
|
30
|
-
Bugsnag.before_notify_callbacks << lambda {|notif|
|
31
|
-
notif.add_custom_data(:info, "here")
|
32
|
-
notif.add_custom_data(:data, "also here")
|
33
|
-
|
34
|
-
callback_run_count += 1
|
35
|
-
}
|
36
|
-
|
37
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
38
|
-
expect(callback_run_count).to eq(1)
|
39
|
-
|
40
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
41
|
-
event = get_event_from_payload(payload)
|
42
|
-
expect(event["metaData"]["custom"]).not_to be_nil
|
43
|
-
expect(event["metaData"]["custom"]["info"]).to eq("here")
|
44
|
-
expect(event["metaData"]["custom"]["data"]).to eq("also here")
|
45
|
-
}
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
it "runs before_bugsnag_notify callbacks, setting the user" do
|
50
|
-
callback_run_count = 0
|
51
|
-
Bugsnag.before_notify_callbacks << lambda {|notif|
|
52
|
-
notif.user = {:id => "here", :email => "also here", :name => "also here too", :random_key => "also here too too"}
|
53
|
-
callback_run_count += 1
|
54
|
-
}
|
55
|
-
|
56
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
57
|
-
expect(callback_run_count).to eq(1)
|
58
|
-
|
59
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
60
|
-
event = get_event_from_payload(payload)
|
61
|
-
expect(event["user"]).not_to be_nil
|
62
|
-
expect(event["user"]["id"]).to eq("here")
|
63
|
-
expect(event["user"]["email"]).to eq("also here")
|
64
|
-
expect(event["user"]["name"]).to eq("also here too")
|
65
|
-
expect(event["user"]["random_key"]).to eq("also here too too")
|
66
|
-
}
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
it "allows overrides to override values set by internal middleware" do
|
71
|
-
Bugsnag.configuration.internal_middleware.use(InternalInfoSetter)
|
72
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"), {:info => "overridden"})
|
73
|
-
|
74
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
75
|
-
event = get_event_from_payload(payload)
|
76
|
-
expect(event["metaData"]["custom"]).not_to be_nil
|
77
|
-
expect(event["metaData"]["custom"]["info"]).not_to eq(InternalInfoSetter::MESSAGE)
|
78
|
-
expect(event["metaData"]["custom"]["info"]).to eq("overridden")
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
it "doesn't allow overrides to override public middleware" do
|
83
|
-
Bugsnag.configuration.middleware.use(PublicInfoSetter)
|
84
|
-
|
85
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"), {:info => "overridden"})
|
86
|
-
|
87
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
88
|
-
event = get_event_from_payload(payload)
|
89
|
-
expect(event["metaData"]["custom"]).not_to be_nil
|
90
|
-
expect(event["metaData"]["custom"]["info"]).not_to eq("overridden")
|
91
|
-
expect(event["metaData"]["custom"]["info"]).to eq(PublicInfoSetter::MESSAGE)
|
92
|
-
}
|
93
|
-
end
|
94
|
-
|
95
|
-
it "does not have have before or after callbacks by default" do
|
96
|
-
expect(Bugsnag.before_notify_callbacks.size).to eq(0)
|
97
|
-
expect(Bugsnag.after_notify_callbacks.size).to eq(0)
|
98
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
99
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
100
|
-
event = get_event_from_payload(payload)
|
101
|
-
expect(event["metaData"].size).to eq(0)
|
102
|
-
}
|
103
|
-
end
|
104
|
-
|
105
|
-
it "runs after_bugsnag_notify callbacks" do
|
106
|
-
callback_run_count = 0
|
107
|
-
Bugsnag.after_notify_callbacks << lambda {|notif|
|
108
|
-
callback_run_count += 1
|
109
|
-
}
|
110
|
-
|
111
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
112
|
-
|
113
|
-
expect(callback_run_count).to eq(1)
|
114
|
-
expect(Bugsnag::Notification).to have_sent_notification { }
|
115
|
-
end
|
116
|
-
|
117
|
-
it "does not execute disabled bugsnag middleware" do
|
118
|
-
callback_run_count = 0
|
119
|
-
Bugsnag.configure do |config|
|
120
|
-
config.middleware.disable(Bugsnag::Middleware::Callbacks)
|
121
|
-
end
|
122
|
-
|
123
|
-
Bugsnag.before_notify_callbacks << lambda {|notif|
|
124
|
-
callback_run_count += 1
|
125
|
-
}
|
126
|
-
|
127
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
128
|
-
expect(callback_run_count).to eq(0)
|
129
|
-
end
|
130
|
-
|
131
|
-
it "does not notify if a callback told so" do
|
132
|
-
Bugsnag.before_notify_callbacks << lambda do |notif|
|
133
|
-
notif.ignore!
|
134
|
-
end
|
135
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
136
|
-
expect(Bugsnag::Notification).not_to have_sent_notification { }
|
137
|
-
end
|
138
|
-
|
139
|
-
it "allows inspection of meta_data before ignoring exception" do
|
140
|
-
# Use before notify callbacks as only the callback based metadata is
|
141
|
-
# available to before_notify_callbacks
|
142
|
-
Bugsnag.before_notify_callbacks << lambda do |notif|
|
143
|
-
notif.add_tab(:sidekiq, {:retry_count => 4})
|
144
|
-
end
|
145
|
-
|
146
|
-
Bugsnag.before_notify_callbacks << lambda do |notif|
|
147
|
-
notif.ignore! if notif.meta_data[:sidekiq][:retry_count] > 3
|
148
|
-
end
|
149
|
-
|
150
|
-
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
151
|
-
expect(Bugsnag::Notification).not_to have_sent_notification
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
it "allows meta_data to be modified in a middleware" do
|
156
|
-
MetaDataMunger = Class.new do
|
157
|
-
def initialize(bugsnag)
|
158
|
-
@bugsnag = bugsnag
|
159
|
-
end
|
160
|
-
|
161
|
-
def call(notification)
|
162
|
-
token = notification.meta_data[:sidekiq][:args].first
|
163
|
-
notification.meta_data[:sidekiq][:args] = ["#{token[0...6]}*****#{token[-4..-1]}"]
|
164
|
-
@bugsnag.call(notification)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
Bugsnag.configure do |c|
|
169
|
-
c.middleware.use MetaDataMunger
|
170
|
-
end
|
171
|
-
|
172
|
-
notification = Bugsnag.notify(BugsnagTestException.new("It crashed"), {
|
173
|
-
:sidekiq => {
|
174
|
-
:args => ["abcdef123456abcdef123456abcdef123456"]
|
175
|
-
}
|
176
|
-
})
|
177
|
-
|
178
|
-
expect(notification.meta_data[:sidekiq][:args]).to eq(["abcdef*****3456"])
|
179
|
-
end
|
180
|
-
|
181
|
-
end
|