44from threading import Thread , current_thread
55
66import sentry_sdk
7+ from sentry_sdk import Scope
8+ from sentry_sdk .scope import ScopeType
79from sentry_sdk .integrations import Integration
810from sentry_sdk .utils import (
911 event_from_exception ,
@@ -75,8 +77,8 @@ def sentry_start(self, *a, **kw):
7577 isolation_scope = sentry_sdk .get_isolation_scope ().fork ()
7678 current_scope = sentry_sdk .get_current_scope ().fork ()
7779 else :
78- isolation_scope = None
79- current_scope = None
80+ isolation_scope = Scope ( ty = ScopeType . ISOLATION )
81+ current_scope = Scope ( ty = ScopeType . CURRENT )
8082
8183 # Patching instance methods in `start()` creates a reference cycle if
8284 # done in a naive way. See
@@ -98,7 +100,7 @@ def sentry_start(self, *a, **kw):
98100
99101
100102def _wrap_run (isolation_scope_to_use , current_scope_to_use , old_run_func ):
101- # type: (Optional[ sentry_sdk.Scope], Optional[ sentry_sdk.Scope] , F) -> F
103+ # type: (sentry_sdk.Scope, sentry_sdk.Scope, F) -> F
102104 @wraps (old_run_func )
103105 def run (* a , ** kw ):
104106 # type: (*Any, **Any) -> Any
@@ -110,13 +112,8 @@ def _run_old_run_func():
110112 except Exception :
111113 reraise (* _capture_exception ())
112114
113- if isolation_scope_to_use is not None and current_scope_to_use is not None :
114- with sentry_sdk .use_isolation_scope (isolation_scope_to_use ):
115- with sentry_sdk .use_scope (current_scope_to_use ):
116- return _run_old_run_func ()
117- else :
118- with sentry_sdk .isolation_scope () as scope :
119- scope .clear ()
115+ with sentry_sdk .use_isolation_scope (isolation_scope_to_use ):
116+ with sentry_sdk .use_scope (current_scope_to_use ):
120117 return _run_old_run_func ()
121118
122119 return run # type: ignore
0 commit comments