bugsnag 6.4.0 → 6.5.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.
@@ -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
@@ -23,6 +23,10 @@ def get_event_from_payload(payload)
23
23
  payload["events"].first
24
24
  end
25
25
 
26
+ def get_headers_from_payload(payload)
27
+
28
+ end
29
+
26
30
  def get_exception_from_payload(payload)
27
31
  event = get_event_from_payload(payload)
28
32
  expect(event["exceptions"].size).to eq(1)
@@ -46,6 +50,7 @@ RSpec.configure do |config|
46
50
 
47
51
  config.before(:each) do
48
52
  WebMock.stub_request(:post, "https://notify.bugsnag.com/")
53
+ WebMock.stub_request(:post, "https://sessions.bugsnag.com/")
49
54
 
50
55
  Bugsnag.instance_variable_set(:@configuration, Bugsnag::Configuration.new)
51
56
  Bugsnag.configure do |bugsnag|
@@ -62,10 +67,21 @@ RSpec.configure do |config|
62
67
  end
63
68
  end
64
69
 
70
+ def have_sent_sessions(&matcher)
71
+ have_requested(:post, "https://sessions.bugsnag.com/").with do |request|
72
+ if matcher
73
+ matcher.call([JSON.parse(request.body), request.headers])
74
+ true
75
+ else
76
+ raise "no matcher provided to have_sent_sessions (did you use { })"
77
+ end
78
+ end
79
+ end
80
+
65
81
  def have_sent_notification(&matcher)
66
82
  have_requested(:post, "https://notify.bugsnag.com/").with do |request|
67
83
  if matcher
68
- matcher.call JSON.parse(request.body)
84
+ matcher.call([JSON.parse(request.body), request.headers])
69
85
  true
70
86
  else
71
87
  raise "no matcher provided to have_sent_notification (did you use { })"
@@ -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.0
4
+ version: 6.5.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-21 00:00:00.000000000 Z
11
+ date: 2018-01-04 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
@@ -109,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
112
  version: '0'
110
113
  requirements: []
111
114
  rubyforge_project:
112
- rubygems_version: 2.4.8
115
+ rubygems_version: 2.6.13
113
116
  signing_key:
114
117
  specification_version: 4
115
118
  summary: Ruby notifier for bugsnag.com