@@ -20,8 +20,11 @@ import (
2020 "github.com/dapr/durabletask-go/backend/sqlite"
2121 "github.com/dapr/durabletask-go/task"
2222 "github.com/dapr/durabletask-go/tests/utils"
23+ "go.opentelemetry.io/otel"
2324)
2425
26+ var tracer = otel .Tracer ("orchestration-test" )
27+
2528func Test_EmptyOrchestration (t * testing.T ) {
2629 // Registration
2730 r := task .NewTaskRegistry ()
@@ -210,6 +213,57 @@ func Test_SingleActivity(t *testing.T) {
210213 )
211214}
212215
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+
213267func Test_ActivityChain (t * testing.T ) {
214268 // Registration
215269 r := task .NewTaskRegistry ()
0 commit comments