diff --git a/tests/contrib/celery/test_chained_task.py b/tests/contrib/celery/test_chained_task.py index 5fd0c543e72..dd9ff8d2907 100644 --- a/tests/contrib/celery/test_chained_task.py +++ b/tests/contrib/celery/test_chained_task.py @@ -1,15 +1,16 @@ import os -import re import subprocess import time from celery import Celery +import pytest # Ensure that when we call Celery chains, the root span has celery specific span tags # The test_integration.py setup doesn't perfectly mimic the condition of a worker process running. # This test runs the worker as a side so we can check the tracer logs afterwards to ensure expected span results. # See https://github.com/DataDog/dd-trace-py/issues/11479 +@pytest.mark.snapshot() def test_task_chain_task_call_task(): app = Celery("tasks") @@ -46,17 +47,6 @@ def test_task_chain_task_call_task(): ) task_runner_process.wait() + time.sleep(5) # Kill the process so it starts to send traces to the Trace Agent worker_process.kill() - worker_logs = worker_process.stderr.read() - - # Check that the root span was created with one of the Celery specific tags, such as celery.correlation_id - # Some versions of python seem to require escaping when using `re.search`: - old_pattern_match = r"resource=\\'tests.contrib.celery.tasks.fn_a\\' type=\\'worker\\' .* tags=.*correlation_id.*" - new_pattern_match = r"resource=\'tests.contrib.celery.tasks.fn_a\' type=\'worker\' .* tags=.*correlation_id.*" - - pattern_exists = ( - re.search(old_pattern_match, str(worker_logs)) is not None - or re.search(new_pattern_match, str(worker_logs)) is not None - ) - assert pattern_exists is not None diff --git a/tests/snapshots/tests.contrib.celery.test_chained_task.test_task_chain_task_call_task.json b/tests/snapshots/tests.contrib.celery.test_chained_task.test_task_chain_task_call_task.json new file mode 100644 index 00000000000..ded35e4720e --- /dev/null +++ b/tests/snapshots/tests.contrib.celery.test_chained_task.test_task_chain_task_call_task.json @@ -0,0 +1,72 @@ +[[ + { + "name": "celery.apply", + "service": "celery-producer", + "resource": "tests.contrib.celery.tasks.fn_a", + "trace_id": 0, + "span_id": 1, + "parent_id": 0, + "type": "", + "error": 0, + "meta": { + "_dd.base_service": "tests.contrib.celery", + "_dd.p.dm": "-0", + "_dd.p.tid": "68b1fefb00000000", + "celery.action": "apply_async", + "celery.hostname": "gen889@docker-desktop", + "celery.id": "fd7fce76-4926-4c09-a21b-fdb21b8b9c82", + "celery.routing_key": "celery", + "component": "celery", + "language": "python", + "runtime-id": "bbe601a62006451db03c410166d55e8c", + "span.kind": "producer" + }, + "metrics": { + "_dd.measured": 1, + "_dd.top_level": 1, + "_dd.tracer_kr": 1.0, + "_sampling_priority_v1": 1, + "process_id": 889 + }, + "duration": 3710917, + "start": 1756495611947254834 + }], +[ + { + "name": "celery.run", + "service": "celery-worker", + "resource": "tests.contrib.celery.tasks.fn_b", + "trace_id": 1, + "span_id": 1, + "parent_id": 0, + "type": "worker", + "error": 0, + "meta": { + "_dd.base_service": "", + "_dd.p.dm": "-0", + "_dd.p.tid": "68b1fefa00000000", + "celery.action": "run", + "celery.correlation_id": "f7ba6425-a8a1-4027-900a-1b95ebce4f14", + "celery.delivery_info.exchange": "", + "celery.delivery_info.redelivered": "True", + "celery.delivery_info.routing_key": "celery", + "celery.hostname": "celery@uniquename1", + "celery.id": "f7ba6425-a8a1-4027-900a-1b95ebce4f14", + "celery.reply_to": "9ee3a3f6-4169-366b-babf-8a7c5e96fec4", + "celery.state": "SUCCESS", + "component": "celery", + "language": "python", + "runtime-id": "8ca15e6906d5448dba188561a52e802a", + "span.kind": "consumer" + }, + "metrics": { + "_dd.measured": 1, + "_dd.top_level": 1, + "_dd.tracer_kr": 1.0, + "_sampling_priority_v1": 1, + "celery.delivery_info.priority": 0, + "process_id": 882 + }, + "duration": 383791, + "start": 1756495610029260667 + }]]