Skip to content

Commit 25de71e

Browse files
ref(logging): Lower logger level for some messages (#3305)
These messages might blow up in volume. This might end up clogging up users' logs. Let's only emit them if debug mode is on. --------- Co-authored-by: Anton Pirker <[email protected]>
1 parent 52e4e23 commit 25de71e

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

sentry_sdk/tracing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def _possibly_started(self):
806806
def __enter__(self):
807807
# type: () -> Transaction
808808
if not self._possibly_started():
809-
logger.warning(
809+
logger.debug(
810810
"Transaction was entered without being started with sentry_sdk.start_transaction."
811811
"The transaction will not be sent to Sentry. To fix, start the transaction by"
812812
"passing it to sentry_sdk.start_transaction."

sentry_sdk/tracing_utils.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ async def func_with_tracing(*args, **kwargs):
637637
span = get_current_span()
638638

639639
if span is None:
640-
logger.warning(
641-
"Can not create a child span for %s. "
640+
logger.debug(
641+
"Cannot create a child span for %s. "
642642
"Please start a Sentry transaction before calling this function.",
643643
qualname_from_function(func),
644644
)
@@ -665,8 +665,8 @@ def func_with_tracing(*args, **kwargs):
665665
span = get_current_span()
666666

667667
if span is None:
668-
logger.warning(
669-
"Can not create a child span for %s. "
668+
logger.debug(
669+
"Cannot create a child span for %s. "
670670
"Please start a Sentry transaction before calling this function.",
671671
qualname_from_function(func),
672672
)

tests/tracing/test_decorator.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ def test_trace_decorator():
3333

3434
def test_trace_decorator_no_trx():
3535
with patch_start_tracing_child(fake_transaction_is_none=True):
36-
with mock.patch.object(logger, "warning", mock.Mock()) as fake_warning:
36+
with mock.patch.object(logger, "debug", mock.Mock()) as fake_debug:
3737
result = my_example_function()
38-
fake_warning.assert_not_called()
38+
fake_debug.assert_not_called()
3939
assert result == "return_of_sync_function"
4040

4141
result2 = start_child_span_decorator(my_example_function)()
42-
fake_warning.assert_called_once_with(
43-
"Can not create a child span for %s. "
42+
fake_debug.assert_called_once_with(
43+
"Cannot create a child span for %s. "
4444
"Please start a Sentry transaction before calling this function.",
4545
"test_decorator.my_example_function",
4646
)
@@ -66,14 +66,14 @@ async def test_trace_decorator_async():
6666
@pytest.mark.asyncio
6767
async def test_trace_decorator_async_no_trx():
6868
with patch_start_tracing_child(fake_transaction_is_none=True):
69-
with mock.patch.object(logger, "warning", mock.Mock()) as fake_warning:
69+
with mock.patch.object(logger, "debug", mock.Mock()) as fake_debug:
7070
result = await my_async_example_function()
71-
fake_warning.assert_not_called()
71+
fake_debug.assert_not_called()
7272
assert result == "return_of_async_function"
7373

7474
result2 = await start_child_span_decorator(my_async_example_function)()
75-
fake_warning.assert_called_once_with(
76-
"Can not create a child span for %s. "
75+
fake_debug.assert_called_once_with(
76+
"Cannot create a child span for %s. "
7777
"Please start a Sentry transaction before calling this function.",
7878
"test_decorator.my_async_example_function",
7979
)

tests/tracing/test_misc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def test_transaction_not_started_warning(sentry_init):
412412
with tx:
413413
pass
414414

415-
mock_logger.warning.assert_any_call(
415+
mock_logger.debug.assert_any_call(
416416
"Transaction was entered without being started with sentry_sdk.start_transaction."
417417
"The transaction will not be sent to Sentry. To fix, start the transaction by"
418418
"passing it to sentry_sdk.start_transaction."

0 commit comments

Comments
 (0)