|
1 | 1 | import base64 |
2 | | -import contextvars |
3 | 2 | import copy |
4 | 3 | import json |
5 | 4 | import linecache |
|
84 | 83 |
|
85 | 84 | _installed_modules = None |
86 | 85 |
|
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 | | - |
109 | 86 |
|
110 | 87 | BASE64_ALPHABET = re.compile(r"^[a-zA-Z0-9/+=]*$") |
111 | 88 |
|
@@ -1468,6 +1445,26 @@ def _get_contextvars() -> "Tuple[bool, type]": |
1468 | 1445 | Please refer to https://docs.sentry.io/platforms/python/contextvars/ for more information. |
1469 | 1446 | """ |
1470 | 1447 |
|
| 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 | + |
1471 | 1468 |
|
1472 | 1469 | def qualname_from_function(func: "Callable[..., Any]") -> "Optional[str]": |
1473 | 1470 | """Return the qualified name of func. Works with regular function, lambda, partial and partialmethod.""" |
|
0 commit comments