bugsnag 6.2.0 → 6.3.0.beta.0
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 +4 -4
- data/VERSION +1 -1
- data/lib/bugsnag.rb +10 -2
- data/lib/bugsnag/configuration.rb +8 -1
- data/lib/bugsnag/delivery/synchronous.rb +107 -6
- data/lib/bugsnag/delivery/thread_queue.rb +2 -2
- data/lib/bugsnag/helpers.rb +24 -0
- data/lib/bugsnag/integrations/rack.rb +1 -0
- data/lib/bugsnag/integrations/rails/controller_methods.rb +1 -0
- data/lib/bugsnag/middleware/session_data.rb +21 -0
- data/lib/bugsnag/report.rb +12 -3
- data/lib/bugsnag/session_tracker.rb +157 -0
- data/spec/configuration_spec.rb +5 -0
- data/spec/integrations/sidekiq_spec.rb +1 -1
- data/spec/middleware_spec.rb +10 -10
- data/spec/rack_spec.rb +2 -2
- data/spec/rails3_request_spec.rb +2 -2
- data/spec/report_spec.rb +61 -61
- data/spec/session_tracker_spec.rb +153 -0
- data/spec/spec_helper.rb +17 -1
- data/spec/stacktrace_spec.rb +5 -5
- metadata +7 -4
@@ -0,0 +1,153 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'webrick'
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
describe Bugsnag::SessionTracker do
|
7
|
+
server = nil
|
8
|
+
queue = Queue.new
|
9
|
+
|
10
|
+
before do
|
11
|
+
@config = Bugsnag::Configuration.new
|
12
|
+
@config.track_sessions = true
|
13
|
+
server = WEBrick::HTTPServer.new :Port => 0, :Logger => WEBrick::Log.new("/dev/null"), :AccessLog => []
|
14
|
+
server.mount_proc '/' do |req, res|
|
15
|
+
headers = []
|
16
|
+
req.each { |header| headers << header }
|
17
|
+
queue << [JSON.parse(req.body), headers]
|
18
|
+
res.status = 202
|
19
|
+
res.body = "OK\n"
|
20
|
+
end
|
21
|
+
Thread.new{ server.start }
|
22
|
+
end
|
23
|
+
|
24
|
+
after do
|
25
|
+
Bugsnag.configure do |conf|
|
26
|
+
conf.track_sessions = false
|
27
|
+
conf.delivery_method = :synchronous
|
28
|
+
end
|
29
|
+
server.stop
|
30
|
+
queue.clear
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'does not create session object if disabled' do
|
34
|
+
config = Bugsnag::Configuration.new
|
35
|
+
config.track_sessions = false
|
36
|
+
tracker = Bugsnag::SessionTracker.new(config)
|
37
|
+
tracker.create_session
|
38
|
+
expect(tracker.session_counts.size).to eq(0)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'adds session object to queue' do
|
42
|
+
tracker = Bugsnag::SessionTracker.new(@config)
|
43
|
+
tracker.create_session
|
44
|
+
expect(tracker.session_counts.size).to eq(1)
|
45
|
+
time = tracker.session_counts.keys.last
|
46
|
+
count = tracker.session_counts[time]
|
47
|
+
|
48
|
+
expect(count).to eq(1)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'stores session in thread' do
|
52
|
+
tracker = Bugsnag::SessionTracker.new(@config)
|
53
|
+
tracker.create_session
|
54
|
+
session = Thread.current[Bugsnag::SessionTracker::THREAD_SESSION]
|
55
|
+
expect(session.include? :id).to be true
|
56
|
+
expect(session.include? :startedAt).to be true
|
57
|
+
expect(session.include? :events).to be true
|
58
|
+
expect(session[:events].include? :handled).to be true
|
59
|
+
expect(session[:events].include? :unhandled).to be true
|
60
|
+
expect(session[:events][:handled]).to eq(0)
|
61
|
+
expect(session[:events][:unhandled]).to eq(0)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'gives unique ids to each session' do
|
65
|
+
tracker = Bugsnag::SessionTracker.new(@config)
|
66
|
+
tracker.create_session
|
67
|
+
session_one = Thread.current[Bugsnag::SessionTracker::THREAD_SESSION]
|
68
|
+
tracker.create_session
|
69
|
+
session_two = Thread.current[Bugsnag::SessionTracker::THREAD_SESSION]
|
70
|
+
expect(session_one[:id]).to_not eq(session_two[:id])
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'sends sessions when send_sessions is called' do
|
74
|
+
Bugsnag.configure do |conf|
|
75
|
+
conf.track_sessions = true
|
76
|
+
conf.delivery_method = :thread_queue
|
77
|
+
conf.session_endpoint = "http://localhost:#{server.config[:Port]}"
|
78
|
+
end
|
79
|
+
WebMock.allow_net_connect!
|
80
|
+
Bugsnag.session_tracker.create_session
|
81
|
+
expect(Bugsnag.session_tracker.session_counts.size).to eq(1)
|
82
|
+
Bugsnag.session_tracker.send_sessions
|
83
|
+
expect(Bugsnag.session_tracker.session_counts.size).to eq(0)
|
84
|
+
while queue.empty?
|
85
|
+
sleep(0.05)
|
86
|
+
end
|
87
|
+
payload, headers = queue.pop
|
88
|
+
expect(payload.include?("app")).to be true
|
89
|
+
expect(payload.include?("notifier")).to be true
|
90
|
+
expect(payload.include?("device")).to be true
|
91
|
+
expect(payload.include?("sessionCounts")).to be true
|
92
|
+
expect(payload["sessionCounts"].size).to eq(1)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'sets details from config' do
|
96
|
+
Bugsnag.configure do |conf|
|
97
|
+
conf.track_sessions = true
|
98
|
+
conf.release_stage = "test_stage"
|
99
|
+
conf.delivery_method = :thread_queue
|
100
|
+
conf.session_endpoint = "http://localhost:#{server.config[:Port]}"
|
101
|
+
end
|
102
|
+
WebMock.allow_net_connect!
|
103
|
+
Bugsnag.session_tracker.create_session
|
104
|
+
expect(Bugsnag.session_tracker.session_counts.size).to eq(1)
|
105
|
+
Bugsnag.session_tracker.send_sessions
|
106
|
+
expect(Bugsnag.session_tracker.session_counts.size).to eq(0)
|
107
|
+
while queue.empty?
|
108
|
+
sleep(0.05)
|
109
|
+
end
|
110
|
+
payload, headers = queue.pop
|
111
|
+
notifier = payload["notifier"]
|
112
|
+
expect(notifier.include?("name")).to be true
|
113
|
+
expect(notifier["name"]).to eq(Bugsnag::Report::NOTIFIER_NAME)
|
114
|
+
expect(notifier.include?("url")).to be true
|
115
|
+
expect(notifier["url"]).to eq(Bugsnag::Report::NOTIFIER_URL)
|
116
|
+
expect(notifier.include?("version")).to be true
|
117
|
+
expect(notifier["version"]).to eq(Bugsnag::Report::NOTIFIER_VERSION)
|
118
|
+
|
119
|
+
app = payload["app"]
|
120
|
+
expect(app.include?("releaseStage")).to be true
|
121
|
+
expect(app["releaseStage"]).to eq(Bugsnag.configuration.release_stage)
|
122
|
+
expect(app.include?("version")).to be true
|
123
|
+
expect(app["version"]).to eq(Bugsnag.configuration.app_version)
|
124
|
+
expect(app.include?("type")).to be true
|
125
|
+
expect(app["type"]).to eq(Bugsnag.configuration.app_type)
|
126
|
+
|
127
|
+
device = payload["device"]
|
128
|
+
expect(device.include?("hostname")).to be true
|
129
|
+
expect(device["hostname"]).to eq(Bugsnag.configuration.hostname)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'uses middleware to attach session to notification' do
|
133
|
+
Bugsnag.configure do |conf|
|
134
|
+
conf.track_sessions = true
|
135
|
+
conf.release_stage = "test_stage"
|
136
|
+
end
|
137
|
+
Bugsnag.session_tracker.create_session
|
138
|
+
Bugsnag.notify(BugsnagTestException.new("It crashed"))
|
139
|
+
expect(Bugsnag).to have_sent_notification{ |payload, headers|
|
140
|
+
event = payload["events"][0]
|
141
|
+
expect(event.include?("session")).to be true
|
142
|
+
session = event["session"]
|
143
|
+
expect(session.include?("id")).to be true
|
144
|
+
expect(session.include?("startedAt")).to be true
|
145
|
+
expect(session.include?("events")).to be true
|
146
|
+
sesevents = session['events']
|
147
|
+
expect(sesevents.include?("unhandled")).to be true
|
148
|
+
expect(sesevents["unhandled"]).to eq(0)
|
149
|
+
expect(sesevents.include?("handled")).to be true
|
150
|
+
expect(sesevents["handled"]).to eq(1)
|
151
|
+
}
|
152
|
+
end
|
153
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -21,6 +21,10 @@ def get_event_from_payload(payload)
|
|
21
21
|
payload["events"].first
|
22
22
|
end
|
23
23
|
|
24
|
+
def get_headers_from_payload(payload)
|
25
|
+
|
26
|
+
end
|
27
|
+
|
24
28
|
def get_exception_from_payload(payload)
|
25
29
|
event = get_event_from_payload(payload)
|
26
30
|
expect(event["exceptions"].size).to eq(1)
|
@@ -44,6 +48,7 @@ RSpec.configure do |config|
|
|
44
48
|
|
45
49
|
config.before(:each) do
|
46
50
|
WebMock.stub_request(:post, "https://notify.bugsnag.com/")
|
51
|
+
WebMock.stub_request(:post, "https://sessions.bugsnag.com/")
|
47
52
|
|
48
53
|
Bugsnag.instance_variable_set(:@configuration, Bugsnag::Configuration.new)
|
49
54
|
Bugsnag.configure do |bugsnag|
|
@@ -60,10 +65,21 @@ RSpec.configure do |config|
|
|
60
65
|
end
|
61
66
|
end
|
62
67
|
|
68
|
+
def have_sent_sessions(&matcher)
|
69
|
+
have_requested(:post, "https://sessions.bugsnag.com/").with do |request|
|
70
|
+
if matcher
|
71
|
+
matcher.call([JSON.parse(request.body), request.headers])
|
72
|
+
true
|
73
|
+
else
|
74
|
+
raise "no matcher provided to have_sent_sessions (did you use { })"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
63
79
|
def have_sent_notification(&matcher)
|
64
80
|
have_requested(:post, "https://notify.bugsnag.com/").with do |request|
|
65
81
|
if matcher
|
66
|
-
matcher.call
|
82
|
+
matcher.call([JSON.parse(request.body), request.headers])
|
67
83
|
true
|
68
84
|
else
|
69
85
|
raise "no matcher provided to have_sent_notification (did you use { })"
|
data/spec/stacktrace_spec.rb
CHANGED
@@ -10,7 +10,7 @@ describe Bugsnag::Stacktrace do
|
|
10
10
|
_e = 5
|
11
11
|
_f = 6
|
12
12
|
|
13
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
13
|
+
expect(Bugsnag).to have_sent_notification{ |payload, headers|
|
14
14
|
exception = get_exception_from_payload(payload)
|
15
15
|
starting_line = __LINE__ - 10
|
16
16
|
expect(exception["stacktrace"][1]["code"]).to eq({
|
@@ -30,7 +30,7 @@ describe Bugsnag::Stacktrace do
|
|
30
30
|
|
31
31
|
notify_test_exception
|
32
32
|
|
33
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
33
|
+
expect(Bugsnag).to have_sent_notification{ |payload, headers|
|
34
34
|
exception = get_exception_from_payload(payload)
|
35
35
|
expect(exception["stacktrace"][1]["code"]).to eq(nil)
|
36
36
|
}
|
@@ -39,7 +39,7 @@ describe Bugsnag::Stacktrace do
|
|
39
39
|
it 'should send the first 7 lines of the file for exceptions near the top' do
|
40
40
|
load 'spec/fixtures/crashes/start_of_file.rb' rescue Bugsnag.notify $!
|
41
41
|
|
42
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
42
|
+
expect(Bugsnag).to have_sent_notification{ |payload, headers|
|
43
43
|
exception = get_exception_from_payload(payload)
|
44
44
|
|
45
45
|
expect(exception["stacktrace"][0]["code"]).to eq({
|
@@ -57,7 +57,7 @@ describe Bugsnag::Stacktrace do
|
|
57
57
|
it 'should send the last 7 lines of the file for exceptions near the bottom' do
|
58
58
|
load 'spec/fixtures/crashes/end_of_file.rb' rescue Bugsnag.notify $!
|
59
59
|
|
60
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
60
|
+
expect(Bugsnag).to have_sent_notification{ |payload, headers|
|
61
61
|
exception = get_exception_from_payload(payload)
|
62
62
|
|
63
63
|
expect(exception["stacktrace"][0]["code"]).to eq({
|
@@ -75,7 +75,7 @@ describe Bugsnag::Stacktrace do
|
|
75
75
|
it 'should send the last 7 lines of the file for exceptions near the bottom' do
|
76
76
|
load 'spec/fixtures/crashes/short_file.rb' rescue Bugsnag.notify $!
|
77
77
|
|
78
|
-
expect(Bugsnag).to have_sent_notification{ |payload|
|
78
|
+
expect(Bugsnag).to have_sent_notification{ |payload, headers|
|
79
79
|
exception = get_exception_from_payload(payload)
|
80
80
|
|
81
81
|
expect(exception["stacktrace"][0]["code"]).to eq({
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bugsnag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.3.0.beta.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby notifier for bugsnag.com
|
14
14
|
email: james@bugsnag.com
|
@@ -60,11 +60,13 @@ files:
|
|
60
60
|
- lib/bugsnag/middleware/rack_request.rb
|
61
61
|
- lib/bugsnag/middleware/rails3_request.rb
|
62
62
|
- lib/bugsnag/middleware/rake.rb
|
63
|
+
- lib/bugsnag/middleware/session_data.rb
|
63
64
|
- lib/bugsnag/middleware/sidekiq.rb
|
64
65
|
- lib/bugsnag/middleware/suggestion_data.rb
|
65
66
|
- lib/bugsnag/middleware/warden_user.rb
|
66
67
|
- lib/bugsnag/middleware_stack.rb
|
67
68
|
- lib/bugsnag/report.rb
|
69
|
+
- lib/bugsnag/session_tracker.rb
|
68
70
|
- lib/bugsnag/stacktrace.rb
|
69
71
|
- lib/bugsnag/tasks.rb
|
70
72
|
- lib/bugsnag/tasks/bugsnag.rake
|
@@ -87,6 +89,7 @@ files:
|
|
87
89
|
- spec/rack_spec.rb
|
88
90
|
- spec/rails3_request_spec.rb
|
89
91
|
- spec/report_spec.rb
|
92
|
+
- spec/session_tracker_spec.rb
|
90
93
|
- spec/spec_helper.rb
|
91
94
|
- spec/stacktrace_spec.rb
|
92
95
|
homepage: http://github.com/bugsnag/bugsnag-ruby
|
@@ -104,9 +107,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
107
|
version: 1.9.2
|
105
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
109
|
requirements:
|
107
|
-
- - "
|
110
|
+
- - ">"
|
108
111
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
112
|
+
version: 1.3.1
|
110
113
|
requirements: []
|
111
114
|
rubyforge_project:
|
112
115
|
rubygems_version: 2.6.13
|