Skip to content

Commit 2888c12

Browse files
committed
Move Celery error tests to the functional tests
The celery tests failed on Python 3.11. This is most likely due to this issue in billiard, a celery dependency, about it not working on Python 3.11 because of the error reported in the CI: celery/billiard#377 It's been fixed in billiard 4.1.0, but celery is locked on billiard version lower than 4, so it cannot use this version with the fix. This issue does not arise on the Docker tests, because they use Python 3.9.16. I've moved the error test span event assertions to the error test that is available in the functional tests, and removed the unit test. That way, the build will run successfully.
1 parent 6c6978e commit 2888c12

File tree

2 files changed

+6
-58
lines changed

2 files changed

+6
-58
lines changed

instrumentation/opentelemetry-instrumentation-celery/tests/test_tasks.py

-58
Original file line numberDiff line numberDiff line change
@@ -83,64 +83,6 @@ def test_task(self):
8383
self.assertEqual(consumer.parent.span_id, producer.context.span_id)
8484
self.assertEqual(consumer.context.trace_id, producer.context.trace_id)
8585

86-
def test_task_with_error(self):
87-
CeleryInstrumentor().instrument()
88-
89-
result = task_error.delay()
90-
91-
timeout = time.time() + 60 * 1 # 1 minutes from now
92-
while not result.ready():
93-
if time.time() > timeout:
94-
break
95-
time.sleep(0.05)
96-
97-
spans = self.sorted_spans(self.memory_exporter.get_finished_spans())
98-
self.assertEqual(len(spans), 2)
99-
100-
consumer, producer = spans
101-
102-
self.assertEqual(
103-
consumer.name, "run/tests.celery_test_tasks.task_error"
104-
)
105-
self.assertEqual(consumer.kind, SpanKind.CONSUMER)
106-
self.assertSpanHasAttributes(
107-
consumer,
108-
{
109-
"celery.action": "run",
110-
"celery.state": "FAILURE",
111-
SpanAttributes.MESSAGING_DESTINATION: "celery",
112-
"celery.task_name": "tests.celery_test_tasks.task_error",
113-
},
114-
)
115-
self.assertEqual(consumer.status.status_code, StatusCode.ERROR)
116-
self.assertEqual(len(consumer.events), 1)
117-
event = consumer.events[0]
118-
self.assertEqual(event.name, "exception")
119-
self.assertEqual(
120-
event.attributes[SpanAttributes.EXCEPTION_TYPE], "ExceptionInfo"
121-
)
122-
self.assertIn(SpanAttributes.EXCEPTION_MESSAGE, event.attributes)
123-
124-
self.assertEqual(
125-
producer.name, "apply_async/tests.celery_test_tasks.task_error"
126-
)
127-
self.assertEqual(producer.kind, SpanKind.PRODUCER)
128-
self.assertSpanHasAttributes(
129-
producer,
130-
{
131-
"celery.action": "apply_async",
132-
"celery.task_name": "tests.celery_test_tasks.task_error",
133-
SpanAttributes.MESSAGING_DESTINATION_KIND: "queue",
134-
SpanAttributes.MESSAGING_DESTINATION: "celery",
135-
},
136-
)
137-
self.assertEqual(producer.status.status_code, StatusCode.UNSET)
138-
self.assertEqual(len(producer.events), 0)
139-
140-
self.assertNotEqual(consumer.parent, producer.context)
141-
self.assertEqual(consumer.parent.span_id, producer.context.span_id)
142-
self.assertEqual(consumer.context.trace_id, producer.context.trace_id)
143-
14486
def test_uninstrument(self):
14587
CeleryInstrumentor().instrument()
14688
CeleryInstrumentor().uninstrument()

tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py

+6
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ def fn_task_parameters(user, force_logout=False):
249249
run_span.attributes.get("celery.task_name")
250250
== "test_celery_functional.fn_task_parameters"
251251
)
252+
assert len(run_span.events) == 0
252253

253254

254255
def test_fn_exception(celery_app, memory_exporter):
@@ -275,6 +276,11 @@ def fn_exception():
275276
== "test_celery_functional.fn_exception"
276277
)
277278
assert span.status.status_code == StatusCode.ERROR
279+
assert len(span.events) == 1
280+
event = span.events[0]
281+
assert event.name == "exception"
282+
assert event.attributes[SpanAttributes.EXCEPTION_TYPE] == "ExceptionInfo"
283+
assert SpanAttributes.EXCEPTION_MESSAGE in event.attributes
278284
assert (
279285
span.attributes.get(SpanAttributes.MESSAGING_MESSAGE_ID)
280286
== result.task_id

0 commit comments

Comments
 (0)