11import os
22import time
3+ import warnings
34from threading import Thread , Lock
45from contextlib import contextmanager
56
2122
2223def is_auto_session_tracking_enabled (hub = None ):
2324 # type: (Optional[sentry_sdk.Hub]) -> Union[Any, bool, None]
24- """Utility function to find out if session tracking is enabled."""
25- # TODO: add deprecation warning
25+ """DEPRECATED: Utility function to find out if session tracking is enabled."""
26+
27+ # Internal callers should use private _is_auto_session_tracking_enabled, instead.
28+ warnings .warn (
29+ "This function is deprecated and will be removed in the next major release. "
30+ "There is no public API replacement." ,
31+ DeprecationWarning ,
32+ stacklevel = 2 ,
33+ )
2634
2735 if hub is None :
2836 hub = sentry_sdk .Hub .current
@@ -44,7 +52,9 @@ def auto_session_tracking(hub=None, session_mode="application"):
4452
4553 if hub is None :
4654 hub = sentry_sdk .Hub .current
47- should_track = is_auto_session_tracking_enabled (hub )
55+ with warnings .catch_warnings ():
56+ warnings .simplefilter ("ignore" , DeprecationWarning )
57+ should_track = is_auto_session_tracking_enabled (hub )
4858 if should_track :
4959 hub .start_session (session_mode = session_mode )
5060 try :
@@ -57,12 +67,26 @@ def auto_session_tracking(hub=None, session_mode="application"):
5767def is_auto_session_tracking_enabled_scope (scope ):
5868 # type: (sentry_sdk.Scope) -> bool
5969 """
60- Utility function to find out if session tracking is enabled.
70+ DEPRECATED: Utility function to find out if session tracking is enabled.
71+ """
6172
62- TODO: This uses the new scopes. When the Hub is removed, the function
63- is_auto_session_tracking_enabled should be removed and this function
64- should be renamed to is_auto_session_tracking_enabled.
73+ warnings .warn (
74+ "This function is deprecated and will be removed in the next major release. "
75+ "There is no public API replacement." ,
76+ DeprecationWarning ,
77+ stacklevel = 2 ,
78+ )
79+
80+ # Internal callers should use private _is_auto_session_tracking_enabled, instead.
81+ return _is_auto_session_tracking_enabled (scope )
82+
83+
84+ def _is_auto_session_tracking_enabled (scope ):
85+ # type: (sentry_sdk.Scope) -> bool
6586 """
87+ Utility function to find out if session tracking is enabled.
88+ """
89+
6690 should_track = scope ._force_auto_session_tracking
6791 if should_track is None :
6892 client_options = sentry_sdk .get_client ().options
@@ -81,7 +105,7 @@ def auto_session_tracking_scope(scope, session_mode="application"):
81105 auto_session_tracking should be removed and this function
82106 should be renamed to auto_session_tracking.
83107 """
84- should_track = is_auto_session_tracking_enabled_scope (scope )
108+ should_track = _is_auto_session_tracking_enabled (scope )
85109 if should_track :
86110 scope .start_session (session_mode = session_mode )
87111 try :
0 commit comments