Skip to content

Commit 7c7ab83

Browse files
committed
add capability for the logging integration to use the parameter 'stack_info' (added in Python 3.2). When set to True the stack trace will be retrieved and properly handled
1 parent c2dfbcc commit 7c7ab83

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

sentry_sdk/integrations/logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _emit(self, record):
202202
client_options=client_options,
203203
mechanism={"type": "logging", "handled": True},
204204
)
205-
elif record.exc_info and record.exc_info[0] is None:
205+
elif (record.exc_info and record.exc_info[0] is None) or record.stack_info:
206206
event = {}
207207
hint = {}
208208
with capture_internal_exceptions():

tests/integrations/logging/test_logging.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,14 @@ def test_logging_extra_data_integer_keys(sentry_init, capture_events):
7777
assert event["extra"] == {"1": 1}
7878

7979

80-
def test_logging_stack(sentry_init, capture_events):
80+
@pytest.mark.parametrize(
81+
"enable_stack_trace_kwarg", ({"exc_info": True}, {"stack_info": True})
82+
)
83+
def test_logging_stack_trace(sentry_init, capture_events, enable_stack_kwarg):
8184
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
8285
events = capture_events()
8386

84-
logger.error("first", exc_info=True)
87+
logger.error("first", **enable_stack_kwarg)
8588
logger.error("second")
8689

8790
(

0 commit comments

Comments
 (0)