From 7819f3e094cdfd0efda74168ae2ce53dc170bfe8 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 18 Jul 2024 16:39:26 +0200 Subject: [PATCH 1/4] ref(logging): Lower logger level for some messages --- sentry_sdk/tracing_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index ba20dc8436..4a50f50810 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -637,8 +637,8 @@ async def func_with_tracing(*args, **kwargs): span = get_current_span() if span is None: - logger.warning( - "Can not create a child span for %s. " + logger.debug( + "Cannot create a child span for %s. " "Please start a Sentry transaction before calling this function.", qualname_from_function(func), ) @@ -665,8 +665,8 @@ def func_with_tracing(*args, **kwargs): span = get_current_span() if span is None: - logger.warning( - "Can not create a child span for %s. " + logger.debug( + "Cannot create a child span for %s. " "Please start a Sentry transaction before calling this function.", qualname_from_function(func), ) From 5a113ef502fcd1b58da9f01068e99181c0b7b6db Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 22 Jul 2024 15:13:25 +0200 Subject: [PATCH 2/4] Updated tests --- tests/tracing/test_decorator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index 6c2d337285..feab4945c3 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -33,14 +33,14 @@ def test_trace_decorator(): def test_trace_decorator_no_trx(): with patch_start_tracing_child(fake_transaction_is_none=True): - with mock.patch.object(logger, "warning", mock.Mock()) as fake_warning: + with mock.patch.object(logger, "debug", mock.Mock()) as fake_warning: result = my_example_function() fake_warning.assert_not_called() assert result == "return_of_sync_function" result2 = start_child_span_decorator(my_example_function)() fake_warning.assert_called_once_with( - "Can not create a child span for %s. " + "Cannot create a child span for %s. " "Please start a Sentry transaction before calling this function.", "test_decorator.my_example_function", ) @@ -66,14 +66,14 @@ async def test_trace_decorator_async(): @pytest.mark.asyncio async def test_trace_decorator_async_no_trx(): with patch_start_tracing_child(fake_transaction_is_none=True): - with mock.patch.object(logger, "warning", mock.Mock()) as fake_warning: + with mock.patch.object(logger, "debug", mock.Mock()) as fake_warning: result = await my_async_example_function() fake_warning.assert_not_called() assert result == "return_of_async_function" result2 = await start_child_span_decorator(my_async_example_function)() fake_warning.assert_called_once_with( - "Can not create a child span for %s. " + "Cannot create a child span for %s. " "Please start a Sentry transaction before calling this function.", "test_decorator.my_async_example_function", ) From ff1463b76f7278628881ea79c29000068696dad6 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 22 Jul 2024 15:21:53 +0200 Subject: [PATCH 3/4] Made it a debug message to not spam logs --- sentry_sdk/tracing.py | 2 +- tests/tracing/test_misc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 92d9e7ca49..8e74707608 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -806,7 +806,7 @@ def _possibly_started(self): def __enter__(self): # type: () -> Transaction if not self._possibly_started(): - logger.warning( + logger.debug( "Transaction was entered without being started with sentry_sdk.start_transaction." "The transaction will not be sent to Sentry. To fix, start the transaction by" "passing it to sentry_sdk.start_transaction." diff --git a/tests/tracing/test_misc.py b/tests/tracing/test_misc.py index 6d722e992f..fcfcf31b69 100644 --- a/tests/tracing/test_misc.py +++ b/tests/tracing/test_misc.py @@ -412,7 +412,7 @@ def test_transaction_not_started_warning(sentry_init): with tx: pass - mock_logger.warning.assert_any_call( + mock_logger.debug.assert_any_call( "Transaction was entered without being started with sentry_sdk.start_transaction." "The transaction will not be sent to Sentry. To fix, start the transaction by" "passing it to sentry_sdk.start_transaction." From e68cefc3161560bfb13c5ad67fc5b7a51f1569fc Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 22 Jul 2024 15:22:06 +0200 Subject: [PATCH 4/4] Better var names --- tests/tracing/test_decorator.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index feab4945c3..584268fbdd 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -33,13 +33,13 @@ def test_trace_decorator(): def test_trace_decorator_no_trx(): with patch_start_tracing_child(fake_transaction_is_none=True): - with mock.patch.object(logger, "debug", mock.Mock()) as fake_warning: + with mock.patch.object(logger, "debug", mock.Mock()) as fake_debug: result = my_example_function() - fake_warning.assert_not_called() + fake_debug.assert_not_called() assert result == "return_of_sync_function" result2 = start_child_span_decorator(my_example_function)() - fake_warning.assert_called_once_with( + fake_debug.assert_called_once_with( "Cannot create a child span for %s. " "Please start a Sentry transaction before calling this function.", "test_decorator.my_example_function", @@ -66,13 +66,13 @@ async def test_trace_decorator_async(): @pytest.mark.asyncio async def test_trace_decorator_async_no_trx(): with patch_start_tracing_child(fake_transaction_is_none=True): - with mock.patch.object(logger, "debug", mock.Mock()) as fake_warning: + with mock.patch.object(logger, "debug", mock.Mock()) as fake_debug: result = await my_async_example_function() - fake_warning.assert_not_called() + fake_debug.assert_not_called() assert result == "return_of_async_function" result2 = await start_child_span_decorator(my_async_example_function)() - fake_warning.assert_called_once_with( + fake_debug.assert_called_once_with( "Cannot create a child span for %s. " "Please start a Sentry transaction before calling this function.", "test_decorator.my_async_example_function",