@@ -12,6 +12,7 @@ import (
12
12
"github.com/cschleiden/go-workflows/backend/history"
13
13
"github.com/cschleiden/go-workflows/backend/metrics"
14
14
"github.com/cschleiden/go-workflows/core"
15
+ "github.com/cschleiden/go-workflows/internal/log"
15
16
"github.com/cschleiden/go-workflows/internal/metrickeys"
16
17
im "github.com/cschleiden/go-workflows/internal/metrics"
17
18
"github.com/cschleiden/go-workflows/internal/workflow"
@@ -63,6 +64,8 @@ func (wtw *WorkflowTaskWorker) Start(ctx context.Context) error {
63
64
64
65
// Complete implements TaskWorker.
65
66
func (wtw * WorkflowTaskWorker ) Complete (ctx context.Context , result * workflow.ExecutionResult , t * backend.WorkflowTask ) error {
67
+ logger := wtw .taskLogger (t )
68
+
66
69
state := result .State
67
70
if state == core .WorkflowInstanceStateFinished || state == core .WorkflowInstanceStateContinuedAsNew {
68
71
if t .WorkflowInstanceState != state {
@@ -76,7 +79,7 @@ func (wtw *WorkflowTaskWorker) Complete(ctx context.Context, result *workflow.Ex
76
79
// Workflow is finished, explicitly evict from cache (if one is used)
77
80
if wtw .cache != nil {
78
81
if err := wtw .cache .Evict (ctx , t .WorkflowInstance ); err != nil {
79
- wtw . logger .ErrorContext (ctx , "could not evict workflow executor from cache" , "error" , err )
82
+ logger .ErrorContext (ctx , "could not evict workflow executor from cache" , "error" , err )
80
83
}
81
84
}
82
85
}
@@ -85,7 +88,7 @@ func (wtw *WorkflowTaskWorker) Complete(ctx context.Context, result *workflow.Ex
85
88
86
89
if err := wtw .backend .CompleteWorkflowTask (
87
90
ctx , t , t .WorkflowInstance , state , result .Executed , result .ActivityEvents , result .TimerEvents , result .WorkflowEvents ); err != nil {
88
- wtw . logger .ErrorContext (ctx , "could not complete workflow task" , "error" , err )
91
+ logger .ErrorContext (ctx , "could not complete workflow task" , "error" , err )
89
92
return fmt .Errorf ("completing workflow task: %w" , err )
90
93
}
91
94
@@ -156,7 +159,7 @@ func (wtw *WorkflowTaskWorker) getExecutor(ctx context.Context, t *backend.Workf
156
159
157
160
if ! ok {
158
161
executor , err = workflow .NewExecutor (
159
- wtw .backend . Logger ( ),
162
+ wtw .taskLogger ( t ),
160
163
wtw .backend .Tracer (),
161
164
wtw .registry ,
162
165
wtw .backend .Converter (),
@@ -178,3 +181,11 @@ func (wtw *WorkflowTaskWorker) getExecutor(ctx context.Context, t *backend.Workf
178
181
179
182
return executor , nil
180
183
}
184
+
185
+ func (wtw * WorkflowTaskWorker ) taskLogger (t * backend.WorkflowTask ) * slog.Logger {
186
+ return wtw .logger .With (
187
+ slog .String (log .TaskIDKey , t .ID ),
188
+ slog .String (log .InstanceIDKey , t .WorkflowInstance .InstanceID ),
189
+ slog .String (log .ExecutionIDKey , t .WorkflowInstance .ExecutionID ),
190
+ )
191
+ }
0 commit comments