From f3c8f9f9ed5386bc89d60f781b33011635a5c206 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Wed, 10 Jul 2024 12:03:41 +0200 Subject: [PATCH] ref: Remove Hub from `capture_internal_exception` logic --- sentry_sdk/debug.py | 14 ++++++-------- sentry_sdk/hub.py | 18 ------------------ sentry_sdk/scope.py | 7 +++---- sentry_sdk/utils.py | 11 ++--------- tests/conftest.py | 5 +++-- 5 files changed, 14 insertions(+), 41 deletions(-) diff --git a/sentry_sdk/debug.py b/sentry_sdk/debug.py index c99f85558d..9291813cae 100644 --- a/sentry_sdk/debug.py +++ b/sentry_sdk/debug.py @@ -1,9 +1,8 @@ import sys import logging +import warnings -from sentry_sdk import utils from sentry_sdk.client import _client_init_debug -from sentry_sdk.hub import Hub from sentry_sdk.scope import Scope from sentry_sdk.utils import logger from logging import LogRecord @@ -22,7 +21,6 @@ def init_debug_support(): # type: () -> None if not logger.handlers: configure_logger() - configure_debug_hub() def configure_logger(): @@ -36,8 +34,8 @@ def configure_logger(): def configure_debug_hub(): # type: () -> None - def _get_debug_hub(): - # type: () -> Hub - return Hub.current - - utils._get_debug_hub = _get_debug_hub + warnings.warn( + "configure_debug_hub is deprecated. Please remove calls to it, as it is a no-op.", + DeprecationWarning, + stacklevel=2, + ) diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index f5a87113c2..3dfb79620a 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -414,24 +414,6 @@ def capture_exception(self, error=None, scope=None, **scope_kwargs): return last_event_id - def _capture_internal_exception( - self, exc_info # type: Any - ): - # type: (...) -> Any - """ - .. deprecated:: 2.0.0 - This function is deprecated and will be removed in a future release. - Please use :py:meth:`sentry_sdk.client._Client._capture_internal_exception` instead. - - Capture an exception that is likely caused by a bug in the SDK - itself. - - Duplicated in :py:meth:`sentry_sdk.client._Client._capture_internal_exception`. - - These exceptions do not end up in Sentry and are just logged instead. - """ - logger.error("Internal error in sentry_sdk", exc_info=exc_info) - def add_breadcrumb(self, crumb=None, hint=None, **kwargs): # type: (Optional[Breadcrumb], Optional[BreadcrumbHint], Any) -> None """ diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 5a271eff44..b4274a4e7c 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -1190,10 +1190,9 @@ def capture_exception(self, error=None, scope=None, **scope_kwargs): return None - def _capture_internal_exception( - self, exc_info # type: ExcInfo - ): - # type: (...) -> None + @staticmethod + def _capture_internal_exception(exc_info): + # type: (ExcInfo) -> None """ Capture an exception that is likely caused by a bug in the SDK itself. diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index 935172333f..2079be52cc 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -81,12 +81,6 @@ def json_dumps(data): return json.dumps(data, allow_nan=False, separators=(",", ":")).encode("utf-8") -def _get_debug_hub(): - # type: () -> Optional[sentry_sdk.Hub] - # This function is replaced by debug.py - pass - - def get_git_revision(): # type: () -> Optional[str] try: @@ -198,9 +192,8 @@ def capture_internal_exceptions(): def capture_internal_exception(exc_info): # type: (ExcInfo) -> None - hub = _get_debug_hub() - if hub is not None: - hub._capture_internal_exception(exc_info) + if sentry_sdk.get_client().is_active(): + sentry_sdk.Scope._capture_internal_exception(exc_info) def to_timestamp(value): diff --git a/tests/conftest.py b/tests/conftest.py index eada3bdac7..8a4af3e98c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -78,7 +78,8 @@ def internal_exceptions(request, monkeypatch): if "tests_internal_exceptions" in request.keywords: return - def _capture_internal_exception(self, exc_info): + @staticmethod + def _capture_internal_exception(exc_info): errors.append(exc_info) @request.addfinalizer @@ -89,7 +90,7 @@ def _(): reraise(*e) monkeypatch.setattr( - sentry_sdk.Hub, "_capture_internal_exception", _capture_internal_exception + sentry_sdk.Scope, "_capture_internal_exception", _capture_internal_exception ) return errors