4
4
from threading import Thread , current_thread
5
5
6
6
import sentry_sdk
7
+ from sentry_sdk import Scope
8
+ from sentry_sdk .scope import ScopeType
7
9
from sentry_sdk .integrations import Integration
8
10
from sentry_sdk .utils import (
9
11
event_from_exception ,
17
19
from typing import Any
18
20
from typing import TypeVar
19
21
from typing import Callable
20
- from typing import Optional
21
22
22
23
from sentry_sdk ._types import ExcInfo
23
24
@@ -75,8 +76,8 @@ def sentry_start(self, *a, **kw):
75
76
isolation_scope = sent
8000
ry_sdk .get_isolation_scope ().fork ()
76
77
current_scope = sentry_sdk .get_current_scope ().fork ()
77
78
else :
78
- isolation_scope = None
79
- current_scope = None
79
+ isolation_scope = Scope ( ty = ScopeType . ISOLATION )
80
+ current_scope = Scope ( ty = ScopeType . CURRENT )
80
81
81
82
# Patching instance methods in `start()` creates a reference cycle if
82
83
# done in a naive way. See
@@ -98,7 +99,7 @@ def sentry_start(self, *a, **kw):
98
99
99
100
100
101
def _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
102
+ # type: (sentry_sdk.Scope, sentry_sdk.Scope, F) -> F
102
103
@wraps (old_run_func )
103
104
def run (* a , ** kw ):
104
105
# type: (*Any, **Any) -> Any
@@ -110,13 +111,8 @@ def _run_old_run_func():
110
111
except Exception :
111
112
reraise (* _capture_exception ())
112
113
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 ()
114
+ with sentry_sdk .use_isolation_scope (isolation_scope_to_use ):
115
+ with sentry_sdk .use_scope (current_scope_to_use ):
120
116
return _run_old_run_func ()
121
117
122
118
return run # type: ignore
0 commit comments