Skip to content

Commit

Permalink
add capability for the logging integration to use the parameter 'stac…
Browse files Browse the repository at this point in the history
…k_info' (added in Python 3.2). When set to True the stack trace will be retrieved and properly handled
  • Loading branch information
gmcrocetti committed Nov 6, 2024
1 parent c2dfbcc commit 7c7ab83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
7 changes: 5 additions & 2 deletions tests/integrations/logging/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

(
Expand Down

0 comments on commit 7c7ab83

Please sign in to comment.