diff --git a/sentry_sdk/integrations/logging.py b/sentry_sdk/integrations/logging.py index 5d23440ad1..b792510d6c 100644 --- a/sentry_sdk/integrations/logging.py +++ b/sentry_sdk/integrations/logging.py @@ -202,7 +202,7 @@ def _emit(self, record): client_options=client_options, mechanism={"type": "logging", "handled": True}, ) - elif record.exc_info and record.exc_info[0] is None: + elif (record.exc_info and record.exc_info[0] is None) or record.stack_info: event = {} hint = {} with capture_internal_exceptions(): diff --git a/tests/integrations/logging/test_logging.py b/tests/integrations/logging/test_logging.py index 02eb26a04d..f880c841d7 100644 --- a/tests/integrations/logging/test_logging.py +++ b/tests/integrations/logging/test_logging.py @@ -77,11 +77,14 @@ def test_logging_extra_data_integer_keys(sentry_init, capture_events): assert event["extra"] == {"1": 1} -def test_logging_stack(sentry_init, capture_events): +@pytest.mark.parametrize( + "enable_stack_trace_kwarg", ({"exc_info": True}, {"stack_info": True}) +) +def test_logging_stack_trace(sentry_init, capture_events, enable_stack_kwarg): sentry_init(integrations=[LoggingIntegration()], default_integrations=False) events = capture_events() - logger.error("first", exc_info=True) + logger.error("first", **enable_stack_kwarg) logger.error("second") (