from copy import copy from collections import deque from functools import wraps from itertools import chain
from sentry_sdk.utils import logger, capture_internal_exceptions from sentry_sdk._types import MYPY
if MYPY: from typing import Any from typing import Dict from typing import Optional from typing import Deque from typing import List from typing import Callable from typing import TypeVar
class Scope(object): """The scope holds extra information that should be sent with all
events that belong to it. """
# NOTE: Even though it should not happen, the scope needs to not crash when # accessed by multiple threads. It's fine if it's full of races, but those # races should never make the user application crash. # # The same needs to hold for any accesses of the scope the SDK makes.
@_attr_setter def level(self, value): # type: (Optional[str]) -> None """When set this overrides the level. Deprecated in favor of set_level."""
self._level = value
def set_level(self, value): # type: (Optional[str]) -> None """Sets the level for the scope."""
self._level = value
@_attr_setter def fingerprint(self, value): # type: (Optional[List[str]]) -> None """When set this overrides the default fingerprint."""
self._fingerprint = value
@_attr_setter def transaction(self, value): # type: (Optional[str]) -> None """When set this forces a specific transaction name to be set."""
self._transaction = value
span = self._span if span:
span.transaction = value
@_attr_setter def user(self, value): # type: (Dict[str, Any]) -> None """When set a specific user is bound to the scope. Deprecated in favor of set_user."""
self.set_user(value)
def set_user(self, value): # type: (Dict[str, Any]) -> None """Sets a user for the scope."""
self._user = value if self._session isnotNone:
self._session.update(user=value)
def set_tag(
self,
key, # type: str
value, # type: Any
): # type: (...) -> None """Sets a tag for a key to a specific value."""
self._tags[key] = value
def remove_tag(
self, key # type: str
): # type: (...) -> None """Removes a specific tag."""
self._tags.pop(key, None)
def set_context(
self,
key, # type: str
value, # type: Any
): # type: (...) -> None """Binds a context at a certain key to a specific value."""
self._contexts[key] = value
def set_extra(
self,
key, # type: str
value, # type: Any
): # type: (...) -> None """Sets an extra key to a specific value."""
self._extras[key] = value
def remove_extra(
self, key # type: str
): # type: (...) -> None """Removes a specific extra key."""
self._extras.pop(key, None)
def add_event_processor(
self, func # type: EventProcessor
): # type: (...) -> None """Register a scope local event processor on the scope.
:param func: This function behaves like `before_send.` """ if len(self._event_processors) > 20:
logger.warning( "Too many event processors on scope! Clearing list to free up some memory: %r",
self._event_processors,
) del self._event_processors[:]
self._event_processors.append(func)
def add_error_processor(
self,
func, # type: ErrorProcessor
cls=None, # type: Optional[Type[BaseException]]
): # type: (...) -> None """Register a scope local error processor on the scope.
:param func: A callback that works similar to an event processor but is invoked with the original exception info triple as second argument.
:param cls: Optionally, only process exceptions of this type. """ if cls isnotNone:
cls_ = cls # For mypy.
real_func = func
@_disable_capture def apply_to_event(
self,
event, # type: Event
hint, # type: Hint
): # type: (...) -> Optional[Event] """Applies the information contained on the scope to the given event."""
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.