Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import base64
import contextvars
import copy
import json
import linecache
Expand Down Expand Up @@ -84,29 +83,6 @@

_installed_modules = None

_is_sentry_internal_task = contextvars.ContextVar(
"is_sentry_internal_task", default=False
)

# These exceptions won't set the span status to error if they occur. Use
# register_control_flow_exception to add to this list
_control_flow_exception_classes: "set[type]" = set()


def is_internal_task() -> bool:
return _is_sentry_internal_task.get()


@contextmanager
def mark_sentry_task_internal() -> "Generator[None, None, None]":
"""Context manager to mark a task as Sentry internal."""
token = _is_sentry_internal_task.set(True)
try:
yield
finally:
_is_sentry_internal_task.reset(token)


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

FALSY_ENV_VALUES = frozenset(("false", "f", "n", "no", "off", "0"))
Expand Down Expand Up @@ -1468,6 +1444,26 @@ def _get_contextvars() -> "Tuple[bool, type]":
Please refer to https://docs.sentry.io/platforms/python/contextvars/ for more information.
"""

_is_sentry_internal_task = ContextVar("is_sentry_internal_task", default=False)

# These exceptions won't set the span status to error if they occur. Use
# register_control_flow_exception to add to this list
_control_flow_exception_classes: "set[type]" = set()


def is_internal_task() -> bool:
return _is_sentry_internal_task.get()


@contextmanager
def mark_sentry_task_internal() -> "Generator[None, None, None]":
"""Context manager to mark a task as Sentry internal."""
token = _is_sentry_internal_task.set(True)
try:
yield
finally:
_is_sentry_internal_task.reset(token)


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