From 7f727c72e526fc67a1d355e1e7f225ad26733004 Mon Sep 17 00:00:00 2001 From: Anton Pirker <anton.pirker@sentry.io> Date: Tue, 23 Apr 2024 13:06:21 +0200 Subject: [PATCH 1/2] Restore original behavior by always creating a span --- sentry_sdk/integrations/celery/__init__.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index 7305736d5e..885e4fe7e7 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -243,15 +243,7 @@ def apply_async(*args, **kwargs): task = args[0] - # Do not create a span when the task is a Celery Beat task - # (Because we do not have a transaction in that case) - span_mgr = ( - sentry_sdk.start_span(op=OP.QUEUE_SUBMIT_CELERY, description=task.name) - if not Scope.get_isolation_scope()._name == "celery-beat" - else NoOpMgr() - ) # type: Union[Span, NoOpMgr] - - with span_mgr as span: + with sentry_sdk.start_span(op=OP.QUEUE_SUBMIT_CELERY, description=task.name) as span: kwargs["headers"] = _update_celery_task_headers( kwarg_headers, span, integration.monitor_beat_tasks ) From a51f9a5464aff269382e44a96cbc296f4913b96e Mon Sep 17 00:00:00 2001 From: Anton Pirker <anton.pirker@sentry.io> Date: Tue, 23 Apr 2024 13:15:41 +0200 Subject: [PATCH 2/2] linting --- sentry_sdk/integrations/celery/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/celery/__init__.py b/sentry_sdk/integrations/celery/__init__.py index 885e4fe7e7..74205a0184 100644 --- a/sentry_sdk/integrations/celery/__init__.py +++ b/sentry_sdk/integrations/celery/__init__.py @@ -11,7 +11,7 @@ _patch_redbeat_maybe_due, _setup_celery_beat_signals, ) -from sentry_sdk.integrations.celery.utils import NoOpMgr, _now_seconds_since_epoch +from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch from sentry_sdk.integrations.logging import ignore_logger from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, TRANSACTION_SOURCE_TASK from sentry_sdk._types import TYPE_CHECKING @@ -30,7 +30,6 @@ from typing import List from typing import Optional from typing import TypeVar - from typing import Union from sentry_sdk._types import EventProcessor, Event, Hint, ExcInfo from sentry_sdk.tracing import Span @@ -243,7 +242,9 @@ def apply_async(*args, **kwargs): task = args[0] - with sentry_sdk.start_span(op=OP.QUEUE_SUBMIT_CELERY, description=task.name) as span: + with sentry_sdk.start_span( + op=OP.QUEUE_SUBMIT_CELERY, description=task.name + ) as span: kwargs["headers"] = _update_celery_task_headers( kwarg_headers, span, integration.monitor_beat_tasks )