from typing import overload from sentry_sdk.integrations import Integration from sentry_sdk.utils import Event, Hint, Breadcrumb, BreadcrumbHint from sentry_sdk.consts import ClientConstructor T = TypeVar("T") else: def overload(x): # type: (T) -> T return x _local = ContextVar("sentry_current_hub") # type: ignore _initial_client = None # type: Optional[weakref.ReferenceType[Client]] def _should_send_default_pii(): # type: () -> bool client = Hub.current.client if not client: return False return client.options["send_default_pii"] class _InitGuard(object): def __init__(self, client): # type: (Client) -> None self._client = client
""" Create spans from Django middleware invocations """ from functools import wraps from django import VERSION as DJANGO_VERSION from sentry_sdk import Hub from sentry_sdk.utils import ContextVar, transaction_from_function _import_string_should_wrap_middleware = ContextVar( "import_string_should_wrap_middleware") if DJANGO_VERSION < (1, 7): import_string_name = "import_by_path" else: import_string_name = "import_string" def patch_django_middlewares(): from django.core.handlers import base old_import_string = getattr(base, import_string_name) def sentry_patched_import_string(dotted_path): rv = old_import_string(dotted_path) if _import_string_should_wrap_middleware.get(None): rv = _wrap_middleware(rv, dotted_path)
from typing import Any from typing import Optional from typing import Dict from typing import Tuple from typing import List from typing import Callable from typing import overload from contextlib import ContextManager from sentry_sdk.integrations import Integration else: def overload(x): return x _local = ContextVar("sentry_current_hub") _initial_client = None def _should_send_default_pii(): # type: () -> bool client = Hub.current.client if not client: return False return client.options["send_default_pii"] class _InitGuard(object): def __init__(self, client): self._client = client
HAS_REAL_CONTEXTVARS, CONTEXTVARS_ERROR_MESSAGE, ) from sentry_sdk.tracing import Transaction if MYPY: from typing import Dict from typing import Any from typing import Optional from typing import Callable from typing_extensions import Literal from sentry_sdk._types import Event, Hint _asgi_middleware_applied = ContextVar("sentry_asgi_middleware_applied") _DEFAULT_TRANSACTION_NAME = "generic ASGI request" def _capture_exception(hub, exc): # type: (Hub, Any) -> None # Check client here as it might have been unset while streaming response if hub.client is not None: event, hint = event_from_exception( exc, client_options=hub.client.options, mechanism={ "type": "asgi", "handled": False
def __init__(self): self._last_seen = ContextVar("last-seen")
from sentry_sdk.transport import make_transport from sentry_sdk.consts import DEFAULT_OPTIONS, SDK_INFO from sentry_sdk.integrations import setup_integrations from sentry_sdk.utils import ContextVar if False: from typing import Any from typing import Callable from typing import Dict from typing import Optional from sentry_sdk.consts import ClientOptions from sentry_sdk.scope import Scope from sentry_sdk.utils import Event, Hint _client_init_debug = ContextVar("client_init_debug") def get_options(*args, **kwargs): # type: (*str, **ClientOptions) -> ClientOptions if args and (isinstance(args[0], string_types) or args[0] is None): dsn = args[0] # type: Optional[str] args = args[1:] else: dsn = None rv = dict(DEFAULT_OPTIONS) options = dict(*args, **kwargs) # type: ignore if dsn is not None and options.get("dsn") is None: options["dsn"] = dsn # type: ignore
from sentry_sdk.integrations import setup_integrations from sentry_sdk.utils import ContextVar from sentry_sdk._types import MYPY if MYPY: from typing import Any from typing import Callable from typing import Dict from typing import Optional from sentry_sdk.scope import Scope from sentry_sdk._types import Event, Hint _client_init_debug = ContextVar("client_init_debug") _client_in_capture_event = ContextVar("client_in_capture_event") def _get_options(*args, **kwargs): # type: (*Optional[str], **Any) -> Dict[str, Any] if args and (isinstance(args[0], (text_type, bytes, str)) or args[0] is None): dsn = args[0] # type: Optional[str] args = args[1:] else: dsn = None rv = dict(DEFAULT_OPTIONS) options = dict(*args, **kwargs) # type: ignore if dsn is not None and options.get("dsn") is None: options["dsn"] = dsn # type: ignore
def __init__(self): # type: () -> None self._last_seen = ContextVar("last-seen")
import sys import copy from datetime import datetime from contextlib import contextmanager from sentry_sdk._compat import with_metaclass from sentry_sdk.scope import Scope from sentry_sdk.utils import ( exc_info_from_error, event_from_exception, logger, ContextVar, ) _local = ContextVar("sentry_current_hub") def _get_client_options(): hub = Hub.current if hub and hub.client: return hub.client.options def _should_send_default_pii(): client = Hub.current.client if not client: return False return client.options["send_default_pii"] class HubMeta(type):
from sentry_sdk.api import configure_scope from sentry_sdk.utils import ContextVar from sentry_sdk.integrations import Integration _last_seen = ContextVar("last-seen") class DedupeIntegration(Integration): identifier = "dedupe" def install(self): with configure_scope() as scope: @scope.add_error_processor def processor(event, exc_info): exc = exc_info[1] if _last_seen.get(None) is exc: return _last_seen.set(exc) return event