Skip to content

Commit f3c8f9f

Browse files
ref: Remove Hub from capture_internal_exception logic
1 parent 2a0e883 commit f3c8f9f

File tree

5 files changed

+14
-41
lines changed

5 files changed

+14
-41
lines changed

sentry_sdk/debug.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import sys
22
import logging
3+
import warnings
34

4-
from sentry_sdk import utils
55
from sentry_sdk.client import _client_init_debug
6-
from sentry_sdk.hub import Hub
76
from sentry_sdk.scope import Scope
87
from sentry_sdk.utils import logger
98
from logging import LogRecord
@@ -22,7 +21,6 @@ def init_debug_support():
2221
# type: () -> None
2322
if not logger.handlers:
2423
configure_logger()
25-
configure_debug_hub()
2624

2725

2826
def configure_logger():
@@ -36,8 +34,8 @@ def configure_logger():
3634

3735
def configure_debug_hub():
3836
# type: () -> None
39-
def _get_debug_hub():
40-
# type: () -> Hub
41-
return Hub.current
42-
43-
utils._get_debug_hub = _get_debug_hub
37+
warnings.warn(
38+
"configure_debug_hub is deprecated. Please remove calls to it, as it is a no-op.",
39+
DeprecationWarning,
40+
stacklevel=2,
41+
)

sentry_sdk/hub.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -414,24 +414,6 @@ def capture_exception(self, error=None, scope=None, **scope_kwargs):
414414

415415
return last_event_id
416416

417-
def _capture_internal_exception(
418-
self, exc_info # type: Any
419-
):
420-
# type: (...) -> Any
421-
"""
422-
.. deprecated:: 2.0.0
423-
This function is deprecated and will be removed in a future release.
424-
Please use :py:meth:`sentry_sdk.client._Client._capture_internal_exception` instead.
425-
426-
Capture an exception that is likely caused by a bug in the SDK
427-
itself.
428-
429-
Duplicated in :py:meth:`sentry_sdk.client._Client._capture_internal_exception`.
430-
431-
These exceptions do not end up in Sentry and are just logged instead.
432-
"""
433-
logger.error("Internal error in sentry_sdk", exc_info=exc_info)
434-
435417
def add_breadcrumb(self, crumb=None, hint=None, **kwargs):
436418
# type: (Optional[Breadcrumb], Optional[BreadcrumbHint], Any) -> None
437419
"""

sentry_sdk/scope.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,10 +1190,9 @@ def capture_exception(self, error=None, scope=None, **scope_kwargs):
11901190

11911191
return None
11921192

1193-
def _capture_internal_exception(
1194-
self, exc_info # type: ExcInfo
1195-
):
1196-
# type: (...) -> None
1193+
@staticmethod
1194+
def _capture_internal_exception(exc_info):
1195+
# type: (ExcInfo) -> None
11971196
"""
11981197
Capture an exception that is likely caused by a bug in the SDK
11991198
itself.

sentry_sdk/utils.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,6 @@ def json_dumps(data):
8181
return json.dumps(data, allow_nan=False, separators=(",", ":")).encode("utf-8")
8282

8383

84-
def _get_debug_hub():
85-
# type: () -> Optional[sentry_sdk.Hub]
86-
# This function is replaced by debug.py
87-
pass
88-
89-
9084
def get_git_revision():
9185
# type: () -> Optional[str]
9286
try:
@@ -198,9 +192,8 @@ def capture_internal_exceptions():
198192

199193
def capture_internal_exception(exc_info):
200194
# type: (ExcInfo) -> None
201-
hub = _get_debug_hub()
202-
if hub is not None:
203-
hub._capture_internal_exception(exc_info)
195+
if sentry_sdk.get_client().is_active():
196+
sentry_sdk.Scope._capture_internal_exception(exc_info)
204197

205198

206199
def to_timestamp(value):

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def internal_exceptions(request, monkeypatch):
7878
if "tests_internal_exceptions" in request.keywords:
7979
return
8080

81-
def _capture_internal_exception(self, exc_info):
81+
@staticmethod
82+
def _capture_internal_exception(exc_info):
8283
errors.append(exc_info)
8384

8485
@request.addfinalizer
@@ -89,7 +90,7 @@ def _():
8990
reraise(*e)
9091

9192
monkeypatch.setattr(
92-
sentry_sdk.Hub, "_capture_internal_exception", _capture_internal_exception
93+
sentry_sdk.Scope, "_capture_internal_exception", _capture_internal_exception
9394
)
9495

9596
return errors

0 commit comments

Comments
 (0)