@@ -21,11 +21,14 @@ import (
21
21
"github.com/dapr/durabletask-go/backend/sqlite"
22
22
"github.com/dapr/durabletask-go/client"
23
23
"github.com/dapr/durabletask-go/task"
24
+ "github.com/dapr/durabletask-go/tests/utils"
25
+ "go.opentelemetry.io/otel"
24
26
)
25
27
26
28
var (
27
29
grpcClient * client.TaskHubGrpcClient
28
30
ctx = context .Background ()
31
+ tracer = otel .Tracer ("grpc-test" )
29
32
)
30
33
31
34
// TestMain is the entry point for the test suite. We use this to set up a gRPC server and client instance
@@ -489,3 +492,51 @@ func Test_Grpc_SubOrchestratorRetries(t *testing.T) {
489
492
// With 3 max attempts there will be two retries with 10 millis delay before each
490
493
require .GreaterOrEqual (t , metadata .LastUpdatedAt .AsTime (), metadata .CreatedAt .AsTime ().Add (2 * 10 * time .Millisecond ))
491
494
}
495
+
496
+ func Test_SingleActivity_TaskSpan (t * testing.T ) {
497
+ // Registration
498
+ r := task .NewTaskRegistry ()
499
+ r .AddOrchestratorN ("SingleActivity_TestSpan" , func (ctx * task.OrchestrationContext ) (any , error ) {
500
+ var input string
501
+ if err := ctx .GetInput (& input ); err != nil {
502
+ return nil , err
503
+ }
504
+ var output string
505
+ err := ctx .CallActivity ("SayHello" , task .WithActivityInput (input )).Await (& output )
506
+ return output , err
507
+ })
508
+ r .AddActivityN ("SayHello" , func (ctx task.ActivityContext ) (any , error ) {
509
+ var name string
510
+ if err := ctx .GetInput (& name ); err != nil {
511
+ return nil , err
512
+ }
513
+ _ , childSpan := tracer .Start (ctx .Context (), "activityChild_TestSpan" )
514
+ childSpan .End ()
515
+ return fmt .Sprintf ("Hello, %s!" , name ), nil
516
+ })
517
+
518
+ exporter := utils .InitTracing ()
519
+ cancelListener := startGrpcListener (t , r )
520
+ defer cancelListener ()
521
+
522
+ // Run the orchestration
523
+ id , err := grpcClient .ScheduleNewOrchestration (ctx , "SingleActivity_TestSpan" , api .WithInput ("世界" ), api .WithStartTime (time .Now ()))
524
+ if assert .NoError (t , err ) {
525
+ metadata , err := grpcClient .WaitForOrchestrationCompletion (ctx , id )
526
+ if assert .NoError (t , err ) {
527
+ assert .Equal (t , protos .OrchestrationStatus_ORCHESTRATION_STATUS_COMPLETED , metadata .RuntimeStatus )
528
+ assert .Equal (t , `"Hello, 世界!"` , metadata .Output .Value )
529
+ }
530
+ }
531
+
532
+ // Validate the exported OTel traces
533
+ spans := exporter .GetSpans ().Snapshots ()
534
+ utils .AssertSpanSequence (t , spans ,
535
+ utils .AssertOrchestratorCreated ("SingleActivity_TestSpan" , id ),
536
+ utils .AssertSpan ("activityChild_TestSpan" ),
537
+ utils .AssertActivity ("SayHello" , id , 0 ),
538
+ utils .AssertOrchestratorExecuted ("SingleActivity_TestSpan" , id , "COMPLETED" ),
539
+ )
540
+ // assert child-parent relationship
541
+ assert .Equal (t , spans [1 ].Parent ().SpanID (), spans [2 ].SpanContext ().SpanID ())
542
+ }
0 commit comments