@@ -36,6 +36,7 @@ def tearDown(self):
36
36
CeleryInstrumentor ().uninstrument ()
37
37
self ._worker .stop ()
38
38
self ._thread .join ()
39
+ CeleryInstrumentor ().uninstrument ()
39
40
40
41
def test_task (self ):
41
42
CeleryInstrumentor ().instrument ()
@@ -97,3 +98,52 @@ def test_uninstrument(self):
97
98
98
99
spans = self .memory_exporter .get_finished_spans ()
99
100
self .assertEqual (len (spans ), 0 )
101
+
102
+
103
+ class TestCelerySignatureTask (TestBase ):
104
+ def setUp (self ):
105
+ super ().setUp ()
106
+
107
+ def start_app (* args , ** kwargs ):
108
+ # Add an additional task that will not be registered with parent thread
109
+ @app .task
110
+ def hidden_task (num_a ):
111
+ return num_a * 2
112
+
113
+ self ._worker = app .Worker (app = app , pool = "solo" , concurrency = 1 )
114
+ return self ._worker .start (* args , ** kwargs )
115
+
116
+ self ._thread = threading .Thread (target = start_app )
117
+ self ._worker = app .Worker (app = app , pool = "solo" , concurrency = 1 )
118
+ self ._thread .daemon = True
119
+ self ._thread .start ()
120
+
121
+ def tearDown (self ):
122
+ super ().tearDown ()
123
+ self ._worker .stop ()
124
+ self ._thread .join ()
125
+ CeleryInstrumentor ().uninstrument ()
126
+
127
+ def test_hidden_task (self ):
128
+ # no-op since already instrumented
129
+ CeleryInstrumentor ().instrument ()
130
+
131
+ res = app .signature ("tests.test_tasks.hidden_task" , (2 ,)).apply_async ()
132
+ while not res .ready ():
133
+ time .sleep (0.05 )
134
+ spans = self .sorted_spans (self .memory_exporter .get_finished_spans ())
135
+ self .assertEqual (len (spans ), 2 )
136
+
137
+ consumer , producer = spans
138
+
139
+ self .assertEqual (consumer .name , "run/tests.test_tasks.hidden_task" )
140
+ self .assertEqual (consumer .kind , SpanKind .CONSUMER )
141
+
142
+ self .assertEqual (
143
+ producer .name , "apply_async/tests.test_tasks.hidden_task"
144
+ )
145
+ self .assertEqual (producer .kind , SpanKind .PRODUCER )
146
+
147
+ self .assertNotEqual (consumer .parent , producer .context )
148
+ self .assertEqual (consumer .parent .span_id , producer .context .span_id )
149
+ self .assertEqual (consumer .context .trace_id , producer .context .trace_id )
0 commit comments