From 3ef01689fda23d0f48a374e11f48fc5fd6485980 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Mon, 22 Apr 2024 17:14:24 +0200 Subject: [PATCH] fix(tracing): Correct discarded transaction debug message Transactions that are discarded because `_span_recorder` is `None` can also be discarded because they were not started with `sentry_sdk.start_transaction`. This change updates the debug message accordingly. Fixes GH-3000 --- sentry_sdk/tracing.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index c2ca5de171..6e82d839db 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -748,7 +748,13 @@ def finish(self, hub=None, end_timestamp=None): return None if self._span_recorder is None: - logger.debug("Discarding transaction because sampled = False") + # Explicit check against False needed because self.sampled might be None + if self.sampled is False: + logger.debug("Discarding transaction because sampled = False") + else: + logger.debug( + "Discarding transaction because it was not started with sentry_sdk.start_transaction" + ) # This is not entirely accurate because discards here are not # exclusively based on sample rate but also traces sampler, but