@@ -8,7 +8,10 @@ import (
8
8
"github.com/cschleiden/go-workflows/internal/converter"
9
9
"github.com/cschleiden/go-workflows/internal/fn"
10
10
"github.com/cschleiden/go-workflows/internal/sync"
11
+ "github.com/cschleiden/go-workflows/internal/tracing"
11
12
"github.com/cschleiden/go-workflows/internal/workflowstate"
13
+ "go.opentelemetry.io/otel/attribute"
14
+ "go.opentelemetry.io/otel/trace"
12
15
)
13
16
14
17
type ActivityOptions struct {
@@ -20,13 +23,13 @@ var DefaultActivityOptions = ActivityOptions{
20
23
}
21
24
22
25
// ExecuteActivity schedules the given activity to be executed
23
- func ExecuteActivity [TResult any ](ctx sync. Context , options ActivityOptions , activity interface {}, args ... interface {}) Future [TResult ] {
24
- return withRetries (ctx , options .RetryOptions , func (ctx sync.Context ) Future [TResult ] {
25
- return executeActivity [TResult ](ctx , options , activity , args ... )
26
+ func ExecuteActivity [TResult any ](ctx Context , options ActivityOptions , activity interface {}, args ... interface {}) Future [TResult ] {
27
+ return withRetries (ctx , options .RetryOptions , func (ctx sync.Context , attempt int ) Future [TResult ] {
28
+ return executeActivity [TResult ](ctx , options , attempt , activity , args ... )
26
29
})
27
30
}
28
31
29
- func executeActivity [TResult any ](ctx sync. Context , options ActivityOptions , activity interface {}, args ... interface {}) Future [TResult ] {
32
+ func executeActivity [TResult any ](ctx Context , options ActivityOptions , attempt int , activity interface {}, args ... interface {}) Future [TResult ] {
30
33
f := sync .NewFuture [TResult ]()
31
34
32
35
if ctx .Err () != nil {
@@ -48,10 +51,18 @@ func executeActivity[TResult any](ctx sync.Context, options ActivityOptions, act
48
51
wfState .AddCommand (cmd )
49
52
wfState .TrackFuture (scheduleEventID , workflowstate .AsDecodingSettable (f ))
50
53
54
+ span := tracing .Tracer (ctx ).Start (
55
+ "ExecuteActivity" , trace .WithAttributes (
56
+ attribute .String ("name" , name ),
57
+ attribute .Int64 (tracing .ScheduleEventID , scheduleEventID ),
58
+ attribute .Int ("attempt" , attempt ),
59
+ ))
60
+ defer span .End ()
61
+
51
62
// Handle cancellation
52
63
if d := ctx .Done (); d != nil {
53
64
if c , ok := d .(sync.ChannelInternal [struct {}]); ok {
54
- if _ , ok := c .ReceiveNonBlocking (ctx ); ok {
65
+ if _ , ok := c .ReceiveNonBlocking (); ok {
55
66
// Workflow has been canceled, check if the activity has already been scheduled, no need to schedule otherwise
56
67
if cmd .State () != command .CommandState_Committed {
57
68
cmd .Done ()
0 commit comments