From ac2b1cd45d3b45c85632122f00156a636a5271d2 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Mon, 21 Oct 2024 17:31:03 -0700 Subject: [PATCH] worker: Address sentry_sdk deprecations. https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-configuring https://github.com/getsentry/sentry-python/releases/2.0.0 https://github.com/getsentry/sentry-python/releases/2.15.0 Signed-off-by: Anders Kaseorg --- zerver/management/commands/process_queue.py | 6 +++--- zerver/worker/base.py | 9 ++++----- zerver/worker/missedmessage_emails.py | 6 ++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/zerver/management/commands/process_queue.py b/zerver/management/commands/process_queue.py index 74cdda4740..d72faab662 100644 --- a/zerver/management/commands/process_queue.py +++ b/zerver/management/commands/process_queue.py @@ -9,10 +9,10 @@ from contextlib import contextmanager from types import FrameType from typing import Any +import sentry_sdk from django.conf import settings from django.core.management.base import CommandError from django.utils import autoreload -from sentry_sdk import configure_scope from typing_extensions import override from zerver.lib.management import ZulipBaseCommand @@ -104,7 +104,7 @@ class Command(ZulipBaseCommand): logger.info("Worker %d connecting to queue %s", worker_num, queue_name) with log_and_exit_if_exception(logger, queue_name, threaded=False): worker = get_worker(queue_name, worker_num=worker_num) - with configure_scope() as scope: + with sentry_sdk.isolation_scope() as scope: scope.set_tag("queue_worker", queue_name) scope.set_tag("worker_num", worker_num) @@ -124,7 +124,7 @@ class ThreadedWorker(threading.Thread): @override def run(self) -> None: with ( - configure_scope() as scope, + sentry_sdk.isolation_scope() as scope, log_and_exit_if_exception(self.logger, self.queue_name, threaded=True), ): scope.set_tag("queue_worker", self.queue_name) diff --git a/zerver/worker/base.py b/zerver/worker/base.py index 5d95a0d917..0e2a95a4f7 100644 --- a/zerver/worker/base.py +++ b/zerver/worker/base.py @@ -212,7 +212,7 @@ class QueueProcessingWorker(ABC): flush_per_request_caches() reset_queries() - with sentry_sdk.start_span(description="statistics"): + with sentry_sdk.start_span(name="statistics"): if consume_time_seconds is not None: self.recent_consume_times.append((len(events), consume_time_seconds)) @@ -252,7 +252,7 @@ class QueueProcessingWorker(ABC): # is needed and the worker can proceed. return - with sentry_sdk.configure_scope() as scope: + with sentry_sdk.new_scope() as scope: scope.set_context( "events", { @@ -261,9 +261,8 @@ class QueueProcessingWorker(ABC): }, ) if isinstance(exception, WorkerTimeoutError): - with sentry_sdk.push_scope() as scope: - scope.fingerprint = ["worker-timeout", self.queue_name] - logging.exception(exception, stack_info=True) + scope.fingerprint = ["worker-timeout", self.queue_name] + logging.exception(exception, stack_info=True) else: logging.exception( "Problem handling data on queue %s", self.queue_name, stack_info=True diff --git a/zerver/worker/missedmessage_emails.py b/zerver/worker/missedmessage_emails.py index 079db3923b..9f2b4c40f4 100644 --- a/zerver/worker/missedmessage_emails.py +++ b/zerver/worker/missedmessage_emails.py @@ -197,7 +197,7 @@ class MissedMessageWorker(QueueProcessingWorker): # re-checking the condition. return False - with sentry_sdk.start_span(description="condvar wait") as span: + with sentry_sdk.start_span(name="condvar wait") as span: span.set_data("timeout", timeout) was_notified = self.cv.wait_for(wait_condition, timeout=timeout) span.set_data("was_notified", was_notified) @@ -236,9 +236,7 @@ class MissedMessageWorker(QueueProcessingWorker): len(events), user_profile_id, ) - with sentry_sdk.start_span( - description="sending missedmessage_emails to user" - ) as span: + with sentry_sdk.start_span(name="sending missedmessage_emails to user") as span: span.set_data("user_profile_id", user_profile_id) span.set_data("event_count", len(events)) try: