diff --git a/sentry_sdk/integrations/excepthook.py b/sentry_sdk/integrations/excepthook.py index d638ef2f9f..58abde6614 100644 --- a/sentry_sdk/integrations/excepthook.py +++ b/sentry_sdk/integrations/excepthook.py @@ -3,7 +3,6 @@ import sentry_sdk from sentry_sdk.utils import ( capture_internal_exceptions, - ensure_integration_enabled, event_from_exception, ) from sentry_sdk.integrations import Integration @@ -47,11 +46,16 @@ def setup_once(): def _make_excepthook(old_excepthook): # type: (Excepthook) -> Excepthook - @ensure_integration_enabled(ExcepthookIntegration, old_excepthook) def sentry_sdk_excepthook(type_, value, traceback): # type: (Type[BaseException], BaseException, Optional[TracebackType]) -> None integration = sentry_sdk.get_client().get_integration(ExcepthookIntegration) + # Note: If we replace this with ensure_integration_enabled then + # we break the exceptiongroup backport; + # See: https://github.com/getsentry/sentry-python/issues/3097 + if integration is None: + return old_excepthook(type_, value, traceback) + if _should_send(integration.always_run): with capture_internal_exceptions(): event, hint = event_from_exception(