8000 feat(sessions): Remove deprecated functions · getsentry/sentry-python@85cb6d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85cb6d0

Browse files
feat(sessions): Remove deprecated functions
Remove the deprecated functions from `sessions.py` (this includes all Hub-based logic) and all tests for these functions. BREAKING CHANGE: Remove `sentry_sdk.sessions.auto_session_tracking`. BREAKING CHANGE: Remove `sentry_sdk.sessions.is_auto_session_tracking_enabled`. BREAKING CHANGE: Remove `sentry_sdk.sessions.is_auto_session_tracking_enabled_scope`. BREAKING CHANGE: Remove `sentry_sdk.sessions.is_auto_session_tracking_enabled_scope`. Closes: #3416
1 parent 403e131 commit 85cb6d0

File tree

2 files changed

+1
-189
lines changed

2 files changed

+1
-189
lines changed

sentry_sdk/sessions.py

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import time
3-
import warnings
43
from threading import Thread, Lock
54
from contextlib import contextmanager
65

@@ -17,7 +16,6 @@
1716
from typing import Generator
1817
from typing import List
1918
from typing import Optional
20-
from typing import Union
2119

2220

2321
def _is_auto_session_tracking_enabled(scope):
@@ -52,91 +50,6 @@ def track_session(scope, session_mode="application"):
5250
yield
5351

5452

55-
@contextmanager
56-
def auto_session_tracking(hub=None, session_mode="application"):
57-
# type: (Optional[sentry_sdk.Hub], str) -> Generator[None, None, None]
58-
"""DEPRECATED: Use track_session instead
59-
Starts and stops a session automatically around a block.
60-
"""
61-
warnings.warn(
62-
"This function is deprecated and will be removed in the next major release. "
63-
"Use track_session instead.",
64-
DeprecationWarning,
65-
stacklevel=2,
66-
)
67-
68-
if hub is None:
69-
hub = sentry_sdk.Hub.current
70-
with warnings.catch_warnings():
71-
warnings.simplefilter("ignore", DeprecationWarning)
72-
should_track = is_auto_session_tracking_enabled(hub)
73-
if should_track:
74-
hub.start_session(session_mode=session_mode)
75-
try:
76-
yield
77-
finally:
78-
if should_track:
79-
hub.end_session()
80-
81-
82-
def is_auto_session_tracking_enabled(hub=None):
83-
# type: (Optional[sentry_sdk.Hub]) -> Union[Any, bool, None]
84-
"""DEPRECATED: Utility function to find out if session tracking is enabled."""
85-
86-
# Internal callers should use private _is_auto_session_tracking_enabled, instead.
87-
warnings.warn(
88-
"This function is deprecated and will be removed in the next major release. "
89-
"There is no public API replacement.",
90-
DeprecationWarning,
91-
stacklevel=2,
92-
)
93-
94-
if hub is None:
95-
hub = sentry_sdk.Hub.current
96-
97-
should_track = hub.scope._force_auto_session_tracking
98-
99-
if should_track is None:
100-
client_options = hub.client.options if hub.client else {}
101-
should_track = client_options.get("auto_session_tracking", False)
102-
103-
return should_track
104-
105-
106-
def is_auto_session_tracking_enabled_scope(scope):
107-
# type: (sentry_sdk.Scope) -> bool
108-
"""
109-
DEPRECATED: Utility function to find out if session tracking is enabled.
110-
"""
111-
112-
warnings.warn(
113-
"This function is deprecated and will be removed in the next major release. "
114-
"There is no public API replacement.",
115-
DeprecationWarning,
116-
stacklevel=2,
117-
)
118-
119-
# Internal callers should use private _is_auto_session_tracking_enabled, instead.
120-
return _is_auto_session_tracking_enabled(scope)
121-
122-
123-
@contextmanager
124-
def auto_session_tracking_scope(scope, session_mode="application"):
125-
# type: (sentry_sdk.Scope, str) -> Generator[None, None, None]
126-
"""DEPRECATED: This function is a deprecated alias for track_session.
127-
Starts and stops a session automatically around a block.
128-
"""
129-
130-
warnings.warn(
131-
"This function is a deprecated alias for track_session and will be removed in the next major release.",
132-
DeprecationWarning,
133-
stacklevel=2,
134-
)
135-
136-
with track_session(scope, session_mode=session_mode):
137-
yield
138-
139-
14053
TERMINAL_SESSION_STATES = ("exited", "abnormal", "crashed")
14154
MAX_ENVELOPE_ITEMS = 100
14255

tests/test_sessions.py

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from unittest import mock
22

33
import sentry_sdk
4-
from sentry_sdk.sessions import auto_session_tracking, track_session
4+
from sentry_sdk.sessions import track_session
55

66

77
def sorted_aggregates(item):
@@ -83,47 +83,6 @@ def test_aggregates(sentry_init, capture_envelopes):
8383
assert aggregates[0]["errored"] == 1
8484

8585

86-
def test_aggregates_deprecated(
87-
sentry_init, capture_envelopes, suppress_deprecation_warnings
88-
):
89-
sentry_init(
90-
release="fun-release",
91-
environment="not-fun-env",
92-
)
93-
envelopes = capture_envelopes()
94-
95-
with auto_session_tracking(session_mode="request"):
96-
with sentry_sdk.new_scope() as scope:
97-
try:
98-
scope.set_user({"id": "42"})
99-
raise Exception("all is wrong")
100-
except Exception:
101-
sentry_sdk.capture_exception()
102-
103-
with auto_session_tracking(session_mode="request"):
104-
pass
105-
106-
sentry_sdk.get_isolation_scope().start_session(session_mode="request")
107-
sentry_sdk.get_isolation_scope().end_session()
108-
sentry_sdk.flush()
109-
110-
assert len(envelopes) == 2
111-
assert envelopes[0].get_event() is not None
112-
113-
sess = envelopes[1]
114-
assert len(sess.items) == 1
115-
sess_event = sess.items[0].payload.json
116-
assert sess_event["attrs"] == {
117-
"release": "fun-release",
118-
"environment": "not-fun-env",
119-
}
120-
121-
aggregates = sorted_aggregates(sess_event)
122-
assert len(aggregates) == 1
123-
assert aggregates[0]["exited"] == 2
124-
assert aggregates[0]["errored"] == 1
125-
126-
12786
def test_aggregates_explicitly_disabled_session_tracking_request_mode(
12887
sentry_init, capture_envelopes
12988
):
@@ -157,38 +116,6 @@ def test_aggregates_explicitly_disabled_session_tracking_request_mode(
157116
assert "errored" not in aggregates[0]
158117

159118

160-
def test_aggregates_explicitly_disabled_session_tracking_request_mode_deprecated(
161-
sentry_init, capture_envelopes, suppress_deprecation_warnings
162-
):
163-
sentry_init(
164-
release="fun-release", environment="not-fun-env", auto_session_tracking=False
165-
)
166-
envelopes = capture_envelopes()
167-
168-
with auto_session_tracking(session_mode="request"):
169-
with sentry_sdk.new_scope():
170-
try:
171-
raise Exception("all is wrong")
172-
except Exception:
173-
sentry_sdk.capture_exception()
174-
175-
with auto_session_tracking(session_mode="request"):
176-
pass
177-
178-
sentry_sdk.get_isolation_scope().start_session(session_mode="request")
179-
sentry_sdk.get_isolation_scope().end_session()
180-
sentry_sdk.flush()
181-
182-
sess = envelopes[1]
183-
assert len(sess.items) == 1
184-
sess_event = sess.items[0].payload.json
185-
186-
aggregates = sorted_aggregates(sess_event)
187-
assert len(aggregates) == 1
188-
assert aggregates[0]["exited"] == 1
189-
assert "errored" not in aggregates[0]
190-
191-
192119
def test_no_thread_on_shutdown_no_errors(sentry_init):
193120
sentry_init(
194121
release="fun-release",
@@ -214,31 +141,3 @@ def test_no_thread_on_shutdown_no_errors(sentry_init):
214141
sentry_sdk.get_isolation_scope().start_session(session_mode="request")
215142
sentry_sdk.get_isolation_scope().end_session()
216143
sentry_sdk.flush()
217-
218-
219-
def test_no_thread_on_shutdown_no_errors_deprecated(
220-
sentry_init, suppress_deprecation_warnings
221-
):
222-
sentry_init(
223-
release="fun-release",
224-
environment="not-fun-env",
225-
)
226-
227-
# make it seem like the interpreter is shutting down
228-
with mock.patch(
229-
"threading.Thread.start",
230-
side_effect=RuntimeError("can't create new thread at interpreter shutdown"),
231-
):
232-
with auto_session_tracking(session_mode="request"):
233-
with sentry_sdk.new_scope():
234-
try:
235-
raise Exception("all is wrong")
236-
except Exception:
237-
sentry_sdk.capture_exception()
238-
239-
with auto_session_tracking(session_mode="request"):
240-
pass
241-
242-
sentry_sdk.get_isolation_scope().start_session(session_mode="request")
243-
sentry_sdk.get_isolation_scope().end_session()
244-
sentry_sdk.flush()

0 commit comments

Comments
 (0)
0