worker: Check if Sentry is initialized before calling add_breadcrumb.

Otherwise we get spammed with “Dropped breadcrumb because no client
bound” log messages.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit e8faa4a029)
This commit is contained in:
Anders Kaseorg
2025-04-07 18:56:32 -07:00
committed by Tim Abbott
parent 25c8d2abd0
commit e916abf31e

View File

@@ -173,12 +173,16 @@ class QueueProcessingWorker(ABC):
name=f"consume {self.queue_name}", name=f"consume {self.queue_name}",
custom_sampling_context={"queue": self.queue_name}, custom_sampling_context={"queue": self.queue_name},
): ):
sentry_sdk.add_breadcrumb( if sentry_sdk.is_initialized():
type="debug", sentry_sdk.add_breadcrumb(
category="queue_processor", type="debug",
message=f"Consuming {self.queue_name}", category="queue_processor",
data={"events": events, "local_queue_size": self.get_remaining_local_queue_size()}, message=f"Consuming {self.queue_name}",
) data={
"events": events,
"local_queue_size": self.get_remaining_local_queue_size(),
},
)
try: try:
if self.idle: if self.idle:
# We're reactivating after having gone idle due to emptying the queue. # We're reactivating after having gone idle due to emptying the queue.