@@ -255,13 +255,21 @@ def get_current_scope(cls):
255
255
256
256
Returns the current scope.
257
257
"""
258
- current_scope = _current_scope . get ()
258
+ current_scope = cls . _get_current_scope ()
259
259
if current_scope is None :
260
260
current_scope = Scope (ty = ScopeType .CURRENT )
261
261
_current_scope .set (current_scope )
262
262
263
263
return current_scope
264
264
265
+ @classmethod
266
+ def _get_current_scope (cls ):
267
+ # type: () -> Optional[Scope]
268
+ """
269
+ Returns the current scope without creating a new one. Internal use only.
270
+ """
271
+ return _current_scope .get ()
272
+
265
273
@classmethod
266
274
def set_current_scope (cls , new_current_scope ):
267
275
# type: (Scope) -> None
@@ -281,13 +289,21 @@ def get_isolation_scope(cls):
281
289
282
290
Returns the isolation scope.
283
291
"""
284
- isolation_scope = _isolation_scope . get ()
292
+ isolation_scope = cls . _get_isolation_scope ()
285
293
if isolation_scope is None :
286
294
isolation_scope = Scope (ty = ScopeType .ISOLATION )
287
295
_isolation_scope .set (isolation_scope )
288
296
289
297
return isolation_scope
290
298
299
+ @classmethod
300
+ def _get_isolation_scope (cls ):
301
+ # type: () -> Optional[Scope]
302
+ """
303
+ Returns the isolation scope without creating a new one. Internal use only.
304
+ """
305
+ return _isolation_scope .get ()
306
+
291
307
@classmethod
292
308
def set_isolation_scope (cls , new_isolation_scope ):
293
309
# type: (Scope) -> None
@@ -342,13 +358,11 @@ def _merge_scopes(self, additional_scope=None, additional_scope_kwargs=None):
342
358
final_scope = copy (_global_scope ) if _global_scope is not None else Scope ()
343
359
final_scope ._type = ScopeType .MERGED
344
360
345
- isolation_scope = _isolation_scope .get ()
346
- if isolation_scope is not None :
347
- final_scope .update_from_scope (isolation_scope )
361
+ isolation_scope = self .get_isolation_scope ()
362
+ final_scope .update_from_scope (isolation_scope )
348
363
349
- current_scope = _current_scope .get ()
350
- if current_scope is not None :
351
- final_scope .update_from_scope (current_scope )
364
+ current_scope = self .get_current_scope ()
365
+ final_scope .update_from_scope (current_scope )
352
366
353
367
if self != current_scope and self != isolation_scope :
354
368
final_scope .update_from_scope (self )
@@ -374,7 +388,7 @@ def get_client(cls):
374
388
This checks the current scope, the isolation scope and the global scope for a client.
375
389
If no client is available a :py:class:`sentry_sdk.client.NonRecordingClient` is returned.
376
390
"""
377
- current_scope = _current_scope . get ()
391
+ current_scope = cls . _get_current_scope ()
378
392
try :
379
393
client = current_scope .client
380
394
except AttributeError :
@@ -383,7 +397,7 @@ def get_client(cls):
383
397
if client is not None and client .is_active ():
384
398
return client
385
399
386
- isolation_scope = _isolation_scope . get ()
400
+ isolation_scope = cls . _get_isolation_scope ()
387
401
try :
388
402
client = isolation_scope .client
389
403
except AttributeError :
@@ -1361,8 +1375,8 @@ def run_event_processors(self, event, hint):
1361
1375
1362
1376
if not is_check_in :
1363
1377
# Get scopes without creating them to prevent infinite recursion
1364
- isolation_scope = _isolation_scope . get ()
1365
- current_scope = _current_scope . get ()
1378
+ isolation_scope = self . _get_isolation_scope ()
1379
+ current_scope = self . _get_current_scope ()
1366
1380
1367
1381
event_processors = chain (
1368
1382
global_event_processors ,
0 commit comments