8000 Instantiate new scopes in threading when propagate is false · getsentry/sentry-python@99eb066 · GitHub
[go: up one dir, main page]

Skip to content

Commit 99eb066

Browse files
committed
Instantiate new scopes in threading when propagate is false
1 parent a964676 commit 99eb066

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

sentry_sdk/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from sentry_sdk.scope import Scope
1+
# TODO-neel scope switch
2+
# TODO-neel avoid duplication between api and __init__
3+
from sentry_sdk.opentelemetry.scope import PotelScope as Scope
24
from sentry_sdk.transport import Transport, HttpTransport
35
from sentry_sdk.client import Client
46

sentry_sdk/integrations/threading.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from threading import Thread, current_thread
55

66
import sentry_sdk
7+
from sentry_sdk import Scope
8+
from sentry_sdk.scope import ScopeType
79
from sentry_sdk.integrations import Integration
810
from sentry_sdk.utils import (
911
event_from_exception,
@@ -17,7 +19,6 @@
1719
from typing import Any
1820
from typing import TypeVar
1921
from typing import Callable
20-
from typing import Optional
2122

2223
from sentry_sdk._types import ExcInfo
2324

@@ -75,8 +76,8 @@ def sentry_start(self, *a, **kw):
7576
isolation_scope = sent 8000 ry_sdk.get_isolation_scope().fork()
7677
current_scope = sentry_sdk.get_current_scope().fork()
7778
else:
78-
isolation_scope = None
79-
current_scope = None
79+
isolation_scope = Scope(ty=ScopeType.ISOLATION)
80+
current_scope = Scope(ty=ScopeType.CURRENT)
8081

8182
# Patching instance methods in `start()` creates a reference cycle if
8283
# done in a naive way. See
@@ -98,7 +99,7 @@ def sentry_start(self, *a, **kw):
9899

99100

100101
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
102103
@wraps(old_run_func)
103104
def run(*a, **kw):
104105
# type: (*Any, **Any) -> Any
@@ -110,13 +111,8 @@ def _run_old_run_func():
110111
except Exception:
111112
reraise(*_capture_exception())
112113

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):
120116
return _run_old_run_func()
121117

122118
return run # type: ignore

0 commit comments

Comments
 (0)
0