-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture sessions automatically by default #523
Conversation
…guration is complete
@@ -305,6 +305,7 @@ Metrics/ModuleLength: | |||
Max: 125 | |||
Exclude: | |||
- 'lib/bugsnag/helpers.rb' | |||
- 'lib/bugsnag.rb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note - this exclusion was originally approved in the breadcrumbs/base
branch.
@@ -117,6 +117,7 @@ services: | |||
- BUGSNAG_SESSION_ENDPOINT | |||
- BUGSNAG_TIMEOUT | |||
- CALLBACK_INITIATOR | |||
- USE_DEFAULT_AUTO_CAPTURE_SESSIONS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm having trouble finding where this is set (from searching for USE_DEFAULT_AUTO_CAPTURE_SESSIONS
in this pull request diff)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my bad, I'd removed some tests temporarily and didn't add them back! Pushing up the rest of the tests now.
render json: {} | ||
end | ||
|
||
def hundred |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name this many
or multiple
or something like that so the name still makes sense if you change the number of sessions started.
lib/bugsnag/configuration.rb
Outdated
|
||
## | ||
# @return [Boolean] whether any sessions types will be delivered | ||
attr_reader :send_sessions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a boolean setting/option/attribute with the same name as a public method in SessionTracker
(send_sessions
) might be slightly confusing. It might be preferable to rename this option to something like sessions_enabled
or session_tracking_enabled
instead.
spec/session_tracker_spec.rb
Outdated
expect(Bugsnag.configuration.send_sessions).to eq(false) | ||
expect(Bugsnag.session_tracker.session_counts.size).to eq(0) | ||
Bugsnag.start_session | ||
# expect(Bugsnag.session_tracker.session_counts.size).to eq(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to uncomment this out?
# Enable reset of session_counts between each example | ||
module Bugsnag | ||
class SessionTracker | ||
attr_accessor :session_counts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can avoid opening/monkey-patching this class by having a before
block call Bugsnag.session_tracker.send_sessions
to flush session_counts
, although you will probably need to set the delivery method to synchronous and clear queue
right after the send_sessions
call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, as long as the monkey-patching won't interfere with the tests I don't have a problem with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A risk of monkey patching like this is that someone might introduce app code that uses the extra behavior (Bugsnag::SessionTracker#session_counts=
in this case) and rely on the unit tests to make sure things work, which will be not as accurate as the tests introduce an extra method while the app code doesn't have this extra method.
Alternatively, you can do something similar to the global before(:each)
block in spec_helper.rb and have Bugsnag.instance_variable_set(:@session_tracker, Bugsnag::SessionTracker.new)
in a before
block in this file (which has the benefit that anything in Bugsnag.session_tracker
is reset if more instance variables are added to Bugsnag::SessionTracker
later).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, and I quite like that last suggestion, more so than relying on send_sessions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you remove this monkey patch and the require 'concurrent'
now that you're using Bugsnag.instance_variable_set(:@session_tracker, Bugsnag::SessionTracker.new)
?
Also, I would put it in a before(:each)
instead, then have an after(:all)
so you have something fresh before the first test in this file also.
Then I should receive a request | ||
And the request is a valid for the session tracking API | ||
And the request used the "Ruby Bugsnag Notifier" notifier | ||
And the "Bugsnag-API-Key" header equals "a35a2a72bd230ac0aa0f52715bbdc6aa" | ||
And the sessionCount "startedAt" is a timestamp | ||
And the sessionCount "sessionsStarted" equals 100 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a little prone to non-deterministic failures because the 100 sessions could span across 2 different minutes?
…to 'enable_sessions' to avoid confusion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a couple minor comments, otherwise lgtm, but I disagree with the monkey patch in session_tracker_spec.rb
Then(/^the total sessionStarted count equals (\d+)(?: for request (\d+))?$/) do |value, request_index| | ||
session_counts = read_key_path(find_request(request_index)[:body], "sessionCounts") | ||
total_count = session_counts.inject(0) { |count, session| count += session["sessionsStarted"] } | ||
assert_equal(total_count, value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flip these arguments ((value, total_count)
); the first parameter is expected
and the second is actual
.
# Enable reset of session_counts between each example | ||
module Bugsnag | ||
class SessionTracker | ||
attr_accessor :session_counts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A risk of monkey patching like this is that someone might introduce app code that uses the extra behavior (Bugsnag::SessionTracker#session_counts=
in this case) and rely on the unit tests to make sure things work, which will be not as accurate as the tests introduce an extra method while the app code doesn't have this extra method.
Alternatively, you can do something similar to the global before(:each)
block in spec_helper.rb and have Bugsnag.instance_variable_set(:@session_tracker, Bugsnag::SessionTracker.new)
in a before
block in this file (which has the benefit that anything in Bugsnag.session_tracker
is reset if more instance variables are added to Bugsnag::SessionTracker
later).
spec/configuration_spec.rb
Outdated
|
||
it "should have sensible defaults for session tracking" do | ||
expect(subject.session_endpoint).to eq("https://sessions.bugsnag.com") | ||
describe "disable_sessions" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#disable_sessions
(missing #
)
Goal
Enable automatic session capture by default, and more strictly enforce endpoint setting.