Skip to content

Commit 008ec66

Browse files
committed
test oroborous
1 parent dbbe5ef commit 008ec66

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

Diff for: sentry_sdk/client.py

-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,6 @@ def _capture_experimental_log(self, scope, log):
892892
"error": logging.ERROR,
893893
"fatal": logging.CRITICAL,
894894
}
895-
# Be careful editing this line, you can add infinite logging loops with the logger integration
896895
logger.log(
897896
severity_text_to_logging_level.get(log["severity_text"], logging.DEBUG),
898897
f'[Sentry Logs] {log["body"]}',

Diff for: sentry_sdk/integrations/logging.py

-3
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,6 @@ def emit(self, record):
345345
if not client.options["_experiments"].get("enable_sentry_logs", False):
346346
return
347347

348-
if record.msg.startswith("[Sentry Logs]"):
349-
return # avoid infinite loop when debug is true
350-
351348
SentryLogsHandler._capture_log_from_record(client, record)
352349

353350
@staticmethod

Diff for: tests/test_logs.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import sentry_sdk
88
from sentry_sdk import _experimental_logger as sentry_logger
9-
9+
from sentry_sdk.integrations.logging import LoggingIntegration
1010

1111
minimum_python_37 = pytest.mark.skipif(
1212
sys.version_info < (3, 7), reason="Asyncio tests need Python >= 3.7"
@@ -263,3 +263,21 @@ def test_logger_integration_debug(sentry_init, capture_envelopes):
263263
python_logger.debug("this is %s a template %s", "1", "2")
264264

265265
assert len(envelopes) == 0
266+
267+
268+
@minimum_python_37
269+
def test_no_log_infinite_loop(sentry_init, capture_envelopes):
270+
"""
271+
If 'debug' mode is true, and you set a low log level in the logging integration, there should be no infinite loops.
272+
"""
273+
sentry_init(
274+
_experiments={"enable_sentry_logs": True},
275+
integrations=[LoggingIntegration(level=logging.DEBUG)],
276+
debug=True,
277+
)
278+
envelopes = capture_envelopes()
279+
280+
python_logger = logging.Logger("test-logger")
281+
python_logger.debug("this is %s a template %s", "1", "2")
282+
283+
assert len(envelopes) == 1

0 commit comments

Comments
 (0)