1
1
from unittest import mock
2
2
3
3
import sentry_sdk
4
- from sentry_sdk import Hub
5
4
from sentry_sdk .sessions import auto_session_tracking
6
5
7
6
@@ -15,17 +14,17 @@ def test_basic(sentry_init, capture_envelopes):
15
14
sentry_init (release = "fun-release" , environment = "not-fun-env" )
16
15
envelopes = capture_envelopes ()
17
16
18
- hub = Hub .current
19
- hub .start_session ()
17
+ sentry_sdk .Scope .get_isolation_scope ().start_session ()
20
18
21
19
try :
22
- with hub . configure_scope () as scope :
23
- scope .set_user ({"id" : "42" })
24
- raise Exception ("all is wrong" )
20
+ scope = sentry_sdk . Scope . get_current_scope ()
21
+ scope .set_user ({"id" : "42" })
22
+ raise Exception ("all is wrong" )
25
23
except Exception :
26
- hub .capture_exception ()
27
- hub .end_session ()
28
- hub .flush ()
24
+ sentry_sdk .capture_exception ()
25
+
26
+ sentry_sdk .Scope .get_isolation_scope ().end_session ()
27
+ sentry_sdk .flush ()
29
28
30
29
assert len (envelopes ) == 2
31
30
assert envelopes [0 ].get_event () is not None
@@ -51,22 +50,20 @@ def test_aggregates(sentry_init, capture_envelopes):
51
50
)
52
51
envelopes = capture_envelopes ()
53
52
54
- hub = Hub .current
55
-
56
53
with auto_session_tracking (session_mode = "request" ):
57
54
with sentry_sdk .push_scope ():
58
55
try :
59
- with sentry_sdk .configure_scope () as scope :
60
- scope .set_user ({"id" : "42" })
61
- raise Exception ("all is wrong" )
56
+ scope = sentry_sdk .Scope . get_current_scope ()
57
+ scope .set_user ({"id" : "42" })
58
+ raise Exception ("all is wrong" )
62
59
except Exception :
63
60
sentry_sdk .capture_exception ()
64
61
65
62
with auto_session_tracking (session_mode = "request" ):
66
63
pass
67
64
68
- hub .start_session (session_mode = "request" )
69
- hub .end_session ()
65
+ sentry_sdk . Scope . get_isolation_scope () .start_session (session_mode = "request" )
66
+ sentry_sdk . Scope . get_isolation_scope () .end_session ()
70
67
71
68
sentry_sdk .flush ()
72
69
@@ -95,8 +92,6 @@ def test_aggregates_explicitly_disabled_session_tracking_request_mode(
95
92
)
96
93
envelopes = capture_envelopes ()
97
94
98
- hub = Hub .current
99
-
100
95
with auto_session_tracking (session_mode = "request" ):
101
96
with sentry_sdk .push_scope ():
102
97
try :
@@ -107,8 +102,8 @@ def test_aggregates_explicitly_disabled_session_tracking_request_mode(
107
102
with auto_session_tracking (session_mode = "request" ):
108
103
pass
109
104
110
- hub .start_session (session_mode = "request" )
111
- hub .end_session ()
105
+ sentry_sdk . Scope . get_isolation_scope () .start_session (session_mode = "request" )
106
+ sentry_sdk . Scope . get_isolation_scope () .end_session ()
112
107
113
108
sentry_sdk .flush ()
114
109
@@ -128,8 +123,6 @@ def test_no_thread_on_shutdown_no_errors(sentry_init):
128
123
environment = "not-fun-env" ,
129
124
)
130
125
131
- hub = Hub .current
132
-
133
126
# make it seem like the interpreter is shutting down
134
127
with mock .patch (
135
128
"threading.Thread.start" ,
@@ -145,7 +138,6 @@ def test_no_thread_on_shutdown_no_errors(sentry_init):
145
138
with auto_session_tracking (session_mode = "request" ):
146
139
pass
147
140
148
- hub .start_session (session_mode = "request" )
149
- hub .end_session ()
150
-
141
+ sentry_sdk .Scope .get_isolation_scope ().start_session (session_mode = "request" )
142
+ sentry_sdk .Scope .get_isolation_scope ().end_session ()
151
143
sentry_sdk .flush ()
0 commit comments