Skip to content

Commit cc81d01

Browse files
jrideoutuntitaker
authored andcommitted
Add the stack option back to the Logging integration (getsentry#176)
* fix: Default to sixty seconds if no Retry-After is given * fix: Skip py34
1 parent c1e0ba0 commit cc81d01

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

sentry_sdk/integrations/logging.py

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from sentry_sdk.utils import (
88
to_string,
99
event_from_exception,
10+
current_stacktrace,
1011
capture_internal_exceptions,
1112
)
1213
from sentry_sdk.integrations import Integration
@@ -145,6 +146,17 @@ def _emit(self, record):
145146
client_options=hub.client.options,
146147
mechanism={"type": "logging", "handled": True},
147148
)
149+
elif record.exc_info and record.exc_info[0] is None:
150+
event = {}
151+
hint = None
152+
with capture_internal_exceptions():
153+
event["threads"] = [
154+
{
155+
"stacktrace": current_stacktrace(),
156+
"crashed": False,
157+
"current": True,
158+
}
159+
]
148160
else:
149161
event = {}
150162
hint = None

tests/integrations/logging/test_logging.py

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24
import logging
35

@@ -36,6 +38,7 @@ def test_logging_defaults(integrations, sentry_init, capture_events):
3638
assert event["level"] == "fatal"
3739
assert any(crumb["message"] == "bread" for crumb in event["breadcrumbs"])
3840
assert not any(crumb["message"] == "LOL" for crumb in event["breadcrumbs"])
41+
assert "threads" not in event
3942

4043

4144
def test_logging_extra_data(sentry_init, capture_events):
@@ -53,3 +56,20 @@ def test_logging_extra_data(sentry_init, capture_events):
5356
crumb["message"] == "bread" and crumb["data"] == {"foo": 42}
5457
for crumb in event["breadcrumbs"]
5558
)
59+
60+
61+
@pytest.mark.xfail(sys.version_info[:2] == (3, 4), reason="buggy logging module")
62+
def test_logging_stack(sentry_init, capture_events):
63+
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
64+
events = capture_events()
65+
66+
logger.error("first", exc_info=True)
67+
logger.error("second")
68+
69+
event_with, event_without, = events
70+
71+
assert event_with["level"] == "error"
72+
assert event_with["threads"][0]["stacktrace"]["frames"]
73+
74+
assert event_without["level"] == "error"
75+
assert "threads" not in event_without

0 commit comments

Comments
 (0)