Skip to content

Commit 6bda8a1

Browse files
authored
Merge pull request #220 from yaananth/yaananth-patch-2
add more keys for events while logging
2 parents cf95b44 + 9008bc3 commit 6bda8a1

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

internal/workflow/executor.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,21 @@ func (e *executor) Close() {
282282
}
283283

284284
func (e *executor) executeEvent(event *history.Event) error {
285-
e.logger.Debug("Executing event",
285+
fields := []any{
286286
log.InstanceIDKey, e.workflowState.Instance().InstanceID,
287287
log.EventIDKey, event.ID,
288288
log.SeqIDKey, event.SequenceID,
289289
log.EventTypeKey, event.Type,
290290
log.ScheduleEventIDKey, event.ScheduleEventID,
291291
log.IsReplayingKey, e.workflowState.Replaying(),
292-
)
292+
}
293+
294+
attributesFields := getAttributesLoggingFields(event)
295+
if attributesFields != nil {
296+
fields = append(fields, attributesFields...)
297+
}
298+
299+
e.logger.Debug("Executing event", fields)
293300

294301
var err error
295302

@@ -676,3 +683,30 @@ func (e *executor) createNewEvent(eventType history.EventType, attributes interf
676683
opts...,
677684
)
678685
}
686+
687+
func getAttributesLoggingFields(event *history.Event) []any {
688+
switch event.Type {
689+
case history.EventType_WorkflowExecutionStarted:
690+
attributes := event.Attributes.(*history.ExecutionStartedAttributes)
691+
return []any{
692+
log.WorkflowNameKey, attributes.Name,
693+
}
694+
case history.EventType_SubWorkflowScheduled:
695+
attributes := event.Attributes.(*history.SubWorkflowScheduledAttributes)
696+
return []any{
697+
log.WorkflowNameKey, attributes.Name,
698+
}
699+
case history.EventType_SignalReceived:
700+
attributes := event.Attributes.(*history.SignalReceivedAttributes)
701+
return []any{
702+
log.SignalNameKey, attributes.Name,
703+
}
704+
case history.EventType_ActivityScheduled:
705+
attributes := event.Attributes.(*history.ActivityScheduledAttributes)
706+
return []any{
707+
log.ActivityNameKey, attributes.Name,
708+
}
709+
default:
710+
return nil
711+
}
712+
}

0 commit comments

Comments
 (0)