Skip to content

Commit 2995cea

Browse files
authored
Add logging fields to executor output
1 parent 6720332 commit 2995cea

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

internal/workflow/executor.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,30 @@ func NewExecutor(logger log.Logger, registry *Registry, historyProvider Workflow
6363
}
6464

6565
func (e *executor) ExecuteTask(ctx context.Context, t *task.Workflow) (*ExecutionResult, error) {
66-
e.logger.Debug("Executing workflow task", "task_id", t.ID, "instance_id", t.WorkflowInstance.InstanceID)
66+
logger := e.logger.With("task_id", t.ID, "instance_id", t.WorkflowInstance.InstanceID)
67+
68+
logger.Debug("Executing workflow task")
6769

6870
e.workflowState.ClearCommands()
6971

7072
skipNewEvents := false
7173

7274
if t.LastSequenceID > e.lastSequenceID {
73-
e.logger.Debug("Task has newer history than current state, fetching and replaying history", "task_sequence_id", t.LastSequenceID, "sequence_id", e.lastSequenceID)
75+
logger.Debug("Task has newer history than current state, fetching and replaying history", "task_sequence_id", t.LastSequenceID, "sequence_id", e.lastSequenceID)
7476

7577
h, err := e.historyProvider.GetWorkflowInstanceHistory(ctx, t.WorkflowInstance, &e.lastSequenceID)
7678
if err != nil {
7779
return nil, fmt.Errorf("getting workflow history: %w", err)
7880
}
7981

8082
if err := e.replayHistory(h); err != nil {
81-
e.logger.Error("Error while replaying history", "error", err)
83+
logger.Error("Error while replaying history", "error", err)
8284

8385
// Fail workflow with an error. Skip executing new events, but still go through the commands
8486
e.workflowCompleted(nil, err)
8587
skipNewEvents = true
8688
} else if t.LastSequenceID != e.lastSequenceID {
87-
e.logger.Debug("Task has newer history than current state", "task_sequence_id", t.LastSequenceID, "sequence_id", e.lastSequenceID)
89+
logger.Debug("Task has newer history than current state", "task_sequence_id", t.LastSequenceID, "sequence_id", e.lastSequenceID)
8890

8991
return nil, errors.New("even after fetching history and replaying history executor state does not match task")
9092
}
@@ -103,7 +105,7 @@ func (e *executor) ExecuteTask(ctx context.Context, t *task.Workflow) (*Executio
103105
var err error
104106
executedEvents, err = e.executeNewEvents(toExecute)
105107
if err != nil {
106-
e.logger.Error("Error while executing new events", "error", err)
108+
logger.Error("Error while executing new events", "error", err)
107109

108110
e.workflowCompleted(nil, err)
109111
}
@@ -122,9 +124,7 @@ func (e *executor) ExecuteTask(ctx context.Context, t *task.Workflow) (*Executio
122124
executedEvents[i].SequenceID = e.nextSequenceID()
123125
}
124126

125-
e.logger.Debug("Finished workflow task",
126-
"task_id", t.ID,
127-
"instance_id", t.WorkflowInstance.InstanceID,
127+
logger.Debug("Finished workflow task",
128128
"executed", len(executedEvents),
129129
"last_sequence_id", e.lastSequenceID,
130130
"completed", completed,

0 commit comments

Comments
 (0)