-
Notifications
You must be signed in to change notification settings - Fork 517
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
ref(sessions): Deprecate hub-based sessions.py
logic
#3419
ref(sessions): Deprecate hub-based sessions.py
logic
#3419
Conversation
sentry_sdk/sessions.py
Outdated
should_track = client_options.get("auto_session_tracking", False) | ||
|
||
return should_track | ||
|
||
|
||
@contextmanager | ||
def track_session(scope, session_mode="application"): |
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 originally tried to make the auto_session_tracking
function use the scope based API by default but still be backwards compatible with hub-based API, but implementing this was going to be extremely overcomplicated.
I decided it would be much simpler to just implement a new function to replace auto_session_tracking
instead, hence why I have proposed fully deprecating auto_session_tracking
and auto_session_tracking_scope
and replacing both with the new track_session
.
f946729
to
c0e5fad
Compare
Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time. ❌ Failed Test Results:Completed 12419 tests with View the full list of failed testspy3.7-falcon-v1.4
|
sentry_sdk/sessions.py
Outdated
# TODO: add deprecation warning | ||
|
||
if hub is None: | ||
hub = sentry_sdk.Hub.current |
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.
Imo to deprecate the hub based session tracking we could add a deprecation warning here if hub is not None
and explain that in the next major they can not use the hub
as a parameter in the next major, but can pass a scope
parameter.
When we do the next major we do what is written in the comment in sessions.py:
TODO: This (is_auto_session_tracking_enabled_scope) uses the new scopes. When the Hub is removed, the function is_auto_session_tracking_enabled should be removed and this function should be renamed to is_auto_session_tracking_enabled.
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.
Discussed offline. The is_auto_session_tracking_enabled
deprecation is now in a separate PR (#3428). After clarifying the reasoning for introducing a new function was that it would allow us in our own code to avoid using deprecated APIs, @antonpirker agreed that introducing track_sessions
was a good idea
Make several changes to prepare for fully removing Hubs in the next major: - Deprecate the Hub-based `auto_session_tracking` function, replacing it with a new Scope-based function called `track_session` - Deprecate the scope-based `auto_session_tracking_scope` in favor of the new `track_session` function - Change usages of `auto_session_tracking_scope` to `track_sessions`. There are no usages of `auto_session_tracking` outside of tests. - Run all tests that were previously run against `auto_session_tracking` also against the new `track_session`. Previously, `auto_session_tracking_scope` was completely untested. Fixes #3417
c0e5fad
to
6111f9c
Compare
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.
Looks good!
I left a few comments, please address them before merging.
|
||
sentry_sdk.get_isolation_scope().start_session(session_mode="request") | ||
sentry_sdk.get_isolation_scope().end_session() | ||
sentry_sdk.flush() |
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.
sentry_sdk.flush() | |
sentry_sdk.flush() | |
# If we reach this point without error, the test is successful. |
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.
Can you also add this comment to the next test? (can not suggest this change from the github ui)
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.
Accidentally merged before fixed, opened #3430 with this change
with track_session(scope, session_mode="request"): | ||
try: | ||
scope.set_user({"id": "42"}) | ||
raise Exception("all is wrong") | ||
except Exception: | ||
sentry_sdk.capture_exception() | ||
|
||
with sentry_sdk.isolation_scope() as scope: | ||
with track_session(scope, session_mode="request"): | ||
pass | ||
|
||
sentry_sdk.get_isolation_scope().start_session(session_mode="request") | ||
sentry_sdk.get_isolation_scope().end_session() | ||
sentry_sdk.flush() |
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.
Tests are always also a kind of documentation on how to use the code.
Could you add comments to the three sessions to mark what aggregate status is expected for each one of them?
Please add those comments to all similar tests in this file. This will help us in the future (or others) to understand what is going on.
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 just copied these tests from the existing tests, and modified them to call the new API. To be completely honest, I don't really understand these tests or know what aggregate status is expected from them.
Since all I am doing is modifying tests to call the new API (and keeping around a copy to still test the old deprecated API), I think it is out of scope to add this documentation here. But, I think this is a good idea, so I will open a new issue.
Implement suggestion from #3419 (comment).
Make several changes to prepare for fully removing Hubs in the next major: - Deprecate the Hub-based `auto_session_tracking` function, replacing it with a new Scope-based function called `track_session` - Deprecate the scope-based `auto_session_tracking_scope` in favor of the new `track_session` function - Change usages of `auto_session_tracking_scope` to `track_sessions`. There are no usages of `auto_session_tracking` outside of tests. - Run all tests that were previously run against `auto_session_tracking` also against the new `track_session`. Previously, `auto_session_tracking_scope` was completely untested. Fixes #3417
Implement suggestion from #3419 (comment). Co-authored-by: Anton Pirker <anton.pirker@sentry.io>
Make several changes to prepare for fully removing Hubs in the next major: - Deprecate the Hub-based `auto_session_tracking` function, replacing it with a new Scope-based function called `track_session` - Deprecate the scope-based `auto_session_tracking_scope` in favor of the new `track_session` function - Change usages of `auto_session_tracking_scope` to `track_sessions`. There are no usages of `auto_session_tracking` outside of tests. - Run all tests that were previously run against `auto_session_tracking` also against the new `track_session`. Previously, `auto_session_tracking_scope` was completely untested. Fixes getsentry#3417
Implement suggestion from getsentry#3419 (comment). Co-authored-by: Anton Pirker <anton.pirker@sentry.io>
Make several changes to prepare for fully removing Hubs in the next major:
auto_session_tracking
function, replacing it with a new Scope-based function calledtrack_session
auto_session_tracking_scope
in favor of the newtrack_session
functionauto_session_tracking_scope
totrack_sessions
. There are no usages ofauto_session_tracking
outside of tests.auto_session_tracking
also against the newtrack_session
. Previously,auto_session_tracking_scope
was completely untested.Fixes #3417