File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,16 @@ def __enter__(self):
90
90
return scope
91
91
92
92
def __exit__ (self , exc_type , exc_value , tb ):
93
- assert self ._hub .pop_scope_unsafe () == self ._layer , "popped wrong scope"
93
+ layer = self ._hub .pop_scope_unsafe ()
94
+ assert layer [1 ] == self ._layer [1 ], "popped wrong scope"
95
+ if layer [0 ] != self ._layer [0 ]:
96
+ warning = (
97
+ "init() called inside of pushed scope. This might be entirely "
98
+ "legitimate but usually occurs when initializing the SDK inside "
99
+ "a request handler or task/job function. Try to initialize the "
100
+ "SDK as early as possible instead."
101
+ )
102
+ logger .warning (warning )
94
103
95
104
96
105
class Hub (with_metaclass (HubMeta )):
Original file line number Diff line number Diff line change @@ -224,3 +224,16 @@ def test_integration_scoping():
224
224
logger .warning ("This is not a warning" )
225
225
226
226
assert len (events ) == 1
227
+
228
+
229
+ def test_client_initialized_within_scope (sentry_init , capture_events , caplog ):
230
+ caplog .set_level (logging .WARNING )
231
+
232
+ sentry_init (debug = True )
233
+
234
+ with push_scope ():
235
+ sentry_init ()
236
+
237
+ record , = (x for x in caplog .records if x .levelname == "WARNING" )
238
+
239
+ assert record .msg .startswith ("init() called inside of pushed scope." )
You can’t perform that action at this time.
0 commit comments