Skip to content

Commit 200d0cd

Browse files
authored
Handle parameter stack_info for the LoggingIntegration
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. Fixes #2804
1 parent c2dfbcc commit 200d0cd

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,18 @@ 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",
82+
(
83+
pytest.param({"exc_info": True}, id="exc_info"),
84+
pytest.param({"stack_info": True}, id="stack_info"),
85+
),
86+
)
87+
def test_logging_stack_trace(sentry_init, capture_events, enable_stack_trace_kwarg):
8188
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
8289
events = capture_events()
8390

84-
logger.error("first", exc_info=True)
91+
logger.error("first", **enable_stack_trace_kwarg)
8592
logger.error("second")
8693

8794
(

0 commit comments

Comments
 (0)