Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref: Remove Hub from capture_internal_exception logic #3264

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: Any
):
# type: (...) -> Any
@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
Loading