Skip to content

Commit fdb2bb3

Browse files
.
1 parent 45fbf90 commit fdb2bb3

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

sentry_sdk/utils.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import base64
2-
import contextvars
32
import copy
43
import json
54
import linecache
@@ -84,28 +83,6 @@
8483

8584
_installed_modules = None
8685

87-
_is_sentry_internal_task = contextvars.ContextVar(
88-
"is_sentry_internal_task", default=False
89-
)
90-
91-
# These exceptions won't set the span status to error if they occur. Use
92-
# register_control_flow_exception to add to this list
93-
_control_flow_exception_classes: "set[type]" = set()
94-
95-
96-
def is_internal_task() -> bool:
97-
return _is_sentry_internal_task.get()
98-
99-
100-
@contextmanager
101-
def mark_sentry_task_internal() -> "Generator[None, None, None]":
102-
"""Context manager to mark a task as Sentry internal."""
103-
token = _is_sentry_internal_task.set(True)
104-
try:
105-
yield
106-
finally:
107-
_is_sentry_internal_task.reset(token)
108-
10986

11087
BASE64_ALPHABET = re.compile(r"^[a-zA-Z0-9/+=]*$")
11188

@@ -1468,6 +1445,26 @@ def _get_contextvars() -> "Tuple[bool, type]":
14681445
Please refer to https://docs.sentry.io/platforms/python/contextvars/ for more information.
14691446
"""
14701447

1448+
_is_sentry_internal_task = ContextVar("is_sentry_internal_task", default=False)
1449+
1450+
# These exceptions won't set the span status to error if they occur. Use
1451+
# register_control_flow_exception to add to this list
1452+
_control_flow_exception_classes: "set[type]" = set()
1453+
1454+
1455+
def is_internal_task() -> bool:
1456+
return _is_sentry_internal_task.get()
1457+
1458+
1459+
@contextmanager
1460+
def mark_sentry_task_internal() -> "Generator[None, None, None]":
1461+
"""Context manager to mark a task as Sentry internal."""
1462+
token = _is_sentry_internal_task.set(True)
1463+
try:
1464+
yield
1465+
finally:
1466+
_is_sentry_internal_task.reset(token)
1467+
14711468

14721469
def qualname_from_function(func: "Callable[..., Any]") -> "Optional[str]":
14731470
"""Return the qualified name of func. Works with regular function, lambda, partial and partialmethod."""

0 commit comments

Comments
 (0)