Skip to content

Commit

Permalink
ref: Remove Hub from capture_internal_exception logic
Browse files Browse the repository at this point in the history
  • Loading branch information
szokeasaurusrex committed Jul 10, 2024
1 parent b0b5ecc commit c42af29
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 41 deletions.
14 changes: 6 additions & 8 deletions sentry_sdk/debug.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -22,7 +21,6 @@ def init_debug_support():
# type: () -> None
if not logger.handlers:
configure_logger()
configure_debug_hub()


def configure_logger():
Expand All @@ -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,
)
18 changes: 0 additions & 18 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
7 changes: 3 additions & 4 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 2 additions & 9 deletions sentry_sdk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c42af29

Please sign in to comment.