Skip to content

Commit 17715c0

Browse files
authored
Restore original behavior by always creating a span (#3005)
In the original implementation of celery trace propagation we had code to only create a span for the task if it was NOT started by Celery Beat (because there is no transaction created in the beat process, so also not span should be created). See this code: https://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/celery.py#L187-L200 Turns out this has never worked and task_started_from_beat has always been False meaning a span was ALWAYS created. (This did never break anything or caused any troube. When looking into a transaction less future this is also absolutely fine.) So this PR restores now the original behavior by always creating a span.
1 parent 7ef20df commit 17715c0

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

sentry_sdk/integrations/celery/__init__.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
_patch_redbeat_maybe_due,
1212
_setup_celery_beat_signals,
1313
)
14-
from sentry_sdk.integrations.celery.utils import NoOpMgr, _now_seconds_since_epoch
14+
from sentry_sdk.integrations.celery.utils import _now_seconds_since_epoch
1515
from sentry_sdk.integrations.logging import ignore_logger
1616
from sentry_sdk.tracing import BAGGAGE_HEADER_NAME, TRANSACTION_SOURCE_TASK
1717
from sentry_sdk._types import TYPE_CHECKING
@@ -30,7 +30,6 @@
3030
from typing import List
3131
from typing import Optional
3232
from typing import TypeVar
33-
from typing import Union
3433

3534
from sentry_sdk._types import EventProcessor, Event, Hint, ExcInfo
3635
from sentry_sdk.tracing import Span
@@ -243,15 +242,9 @@ def apply_async(*args, **kwargs):
243242

244243
task = args[0]
245244

246-
# Do not create a span when the task is a Celery Beat task
247-
# (Because we do not have a transaction in that case)
248-
span_mgr = (
249-
sentry_sdk.start_span(op=OP.QUEUE_SUBMIT_CELERY, description=task.name)
250-
if not Scope.get_isolation_scope()._name == "celery-beat"
251-
else NoOpMgr()
252-
) # type: Union[Span, NoOpMgr]
253-
254-
with span_mgr as span:
245+
with sentry_sdk.start_span(
246+
op=OP.QUEUE_SUBMIT_CELERY, description=task.name
247+
) as span:
255248
kwargs["headers"] = _update_celery_task_headers(
256249
kwarg_headers, span, integration.monitor_beat_tasks
257250
)

0 commit comments

Comments
 (0)