@@ -20,8 +20,11 @@ import (
20
20
"github.com/dapr/durabletask-go/backend/sqlite"
21
21
"github.com/dapr/durabletask-go/task"
22
22
"github.com/dapr/durabletask-go/tests/utils"
23
+ "go.opentelemetry.io/otel"
23
24
)
24
25
26
+ var tracer = otel .Tracer ("orchestration-test" )
27
+
25
28
func Test_EmptyOrchestration (t * testing.T ) {
26
29
// Registration
27
30
r := task .NewTaskRegistry ()
@@ -210,6 +213,57 @@ func Test_SingleActivity(t *testing.T) {
210
213
)
211
214
}
212
215
216
+ func Test_SingleActivity_TaskSpan (t * testing.T ) {
217
+ // Registration
218
+ r := task .NewTaskRegistry ()
219
+ r .AddOrchestratorN ("SingleActivity" , func (ctx * task.OrchestrationContext ) (any , error ) {
220
+ var input string
221
+ if err := ctx .GetInput (& input ); err != nil {
222
+ return nil , err
223
+ }
224
+ var output string
225
+ err := ctx .CallActivity ("SayHello" , task .WithActivityInput (input )).Await (& output )
226
+ return output , err
227
+ })
228
+ r .AddActivityN ("SayHello" , func (ctx task.ActivityContext ) (any , error ) {
229
+ var name string
230
+ if err := ctx .GetInput (& name ); err != nil {
231
+ return nil , err
232
+ }
233
+ _ , childSpan := tracer .Start (ctx .Context (), "activityChild" )
234
+ childSpan .End ()
235
+ return fmt .Sprintf ("Hello, %s!" , name ), nil
236
+ })
237
+
238
+ // Initialization
239
+ ctx := context .Background ()
240
+ exporter := utils .InitTracing ()
241
+
242
+ client , worker := initTaskHubWorker (ctx , r )
243
+ defer worker .Shutdown (ctx )
244
+
245
+ // Run the orchestration
246
+ id , err := client .ScheduleNewOrchestration (ctx , "SingleActivity" , api .WithInput ("世界" ))
247
+ if assert .NoError (t , err ) {
248
+ metadata , err := client .WaitForOrchestrationCompletion (ctx , id )
249
+ if assert .NoError (t , err ) {
250
+ assert .Equal (t , protos .OrchestrationStatus_ORCHESTRATION_STATUS_COMPLETED , metadata .RuntimeStatus )
251
+ assert .Equal (t , `"Hello, 世界!"` , metadata .Output .Value )
252
+ }
253
+ }
254
+
255
+ // Validate the exported OTel traces
256
+ spans := exporter .GetSpans ().Snapshots ()
257
+ utils .AssertSpanSequence (t , spans ,
258
+ utils .AssertOrchestratorCreated ("SingleActivity" , id ),
259
+ utils .AssertSpan ("activityChild" ),
260
+ utils .AssertActivity ("SayHello" , id , 0 ),
261
+ utils .AssertOrchestratorExecuted ("SingleActivity" , id , "COMPLETED" ),
262
+ )
263
+ // assert child-parent relationship
264
+ assert .Equal (t , spans [1 ].Parent ().SpanID (), spans [2 ].SpanContext ().SpanID ())
265
+ }
266
+
213
267
func Test_ActivityChain (t * testing.T ) {
214
268
// Registration
215
269
r := task .NewTaskRegistry ()
0 commit comments