Skip to content

Commit 38523a3

Browse files
test: add unit tests
Signed-off-by: Shivanshu Raj Shrivastava <[email protected]>
1 parent 1061a83 commit 38523a3

File tree

2 files changed

+37
-1
lines changed
  • instrumentation/opentelemetry-instrumentation-celery

2 files changed

+37
-1
lines changed

instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def add(x, y):
9696
_TASK_REVOKED_TERMINATED_SIGNAL_KEY = "celery.terminated.signal"
9797
_TASK_NAME_KEY = "celery.task_name"
9898

99-
_QUEUE_NAME = "queue"
99+
_QUEUE_NAME = "celery"
100100

101101

102102
class CeleryGetter(Getter):

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

+36
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,42 @@ def test_task(self):
9292
self.assertEqual(consumer.parent.span_id, producer.context.span_id)
9393
self.assertEqual(consumer.context.trace_id, producer.context.trace_id)
9494

95+
def test_queue_name(self):
96+
CeleryInstrumentor().instrument()
97+
98+
result = task_add.delay(1, 2)
99+
100+
timeout = time.time() + 60 * 1 # 1 minutes from now
101+
while not result.ready():
102+
if time.time() > timeout:
103+
break
104+
time.sleep(0.05)
105+
106+
spans = self.sorted_spans(self.memory_exporter.get_finished_spans())
107+
self.assertEqual(len(spans), 2)
108+
109+
consumer, producer = spans
110+
111+
self.assertEqual(consumer.name, "run/tests.celery_test_tasks.task_add")
112+
self.assertEqual(consumer.kind, SpanKind.CONSUMER)
113+
self.assertSpanHasAttributes(
114+
consumer,
115+
{
116+
"celery.action": "run",
117+
"celery.state": "SUCCESS",
118+
SpanAttributes.MESSAGING_SYSTEM: "celery",
119+
"celery.task_name": "tests.celery_test_tasks.task_add",
120+
},
121+
)
122+
self.assertSpanHasAttributes(
123+
producer,
124+
{
125+
"celery.action": "apply_async",
126+
"celery.task_name": "tests.celery_test_tasks.task_add",
127+
SpanAttributes.MESSAGING_SYSTEM: "celery",
128+
},
129+
)
130+
95131
def test_task_raises(self):
96132
CeleryInstrumentor().instrument()
97133

0 commit comments

Comments
 (0)