Skip to content

Commit 060f867

Browse files
committed
fix: capture every RunWorkflowPhase log message in per-phase logs
- Move SetGoroutinePhaseKey + log capture to the top of RunWorkflowPhase so [SKIP], [CANCEL], [INFO], [OK], [WARN], [ERROR] messages are all captured for every module. - Removed the runTracked wrapper; the timeout goroutine now directly sets the phase key so child-goroutine logs are also captured. - Previously only logs from inside the module fn() were captured, leaving many modules with zero log entries because their output goes to subprocess stdout rather than logrus.
1 parent 1aa681e commit 060f867

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

internal/utils/workflow.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ func RunWorkflowPhase(phaseKey string, step, total int, description, target stri
4141
// then falls back to AUTOAR_CURRENT_SCAN_ID env var (subprocess compat).
4242
scanID := GetCurrentScanID()
4343

44+
// Register phase key and log capture immediately so EVERY log message emitted
45+
// by this phase (start, skip, cancel, complete, error, and anything logged by
46+
// the module function) lands in the per-phase log file.
47+
SetGoroutinePhaseKey(phaseKey)
48+
flushLogs := StartPhaseLogCapture(scanID, phaseKey)
49+
defer func() {
50+
ClearGoroutinePhaseKey()
51+
flushLogs()
52+
}()
53+
4454
// Checkpoint: Skip if phase already completed successfully
4555
if scanID != "" && db.IsPhaseCompleted(scanID, description) {
4656
GetLogger().WithField("step", step).WithField("total", total).Infof("[SKIP] %s (already completed)", description)
@@ -67,21 +77,16 @@ func RunWorkflowPhase(phaseKey string, step, total int, description, target stri
6777
_ = db.UpdateScanProgress(scanID, progress)
6878
}
6979

70-
// Helper that runs fn with phase-key tracking and log capture.
71-
runTracked := func(phaseFn func() error) error {
72-
SetGoroutinePhaseKey(phaseKey)
73-
flushLogs := StartPhaseLogCapture(scanID, phaseKey)
74-
defer func() {
75-
ClearGoroutinePhaseKey()
76-
flushLogs()
77-
}()
78-
return phaseFn()
79-
}
80-
8180
var err error
8281
if timeoutSeconds > 0 {
8382
done := make(chan error, 1)
84-
go func() { done <- runTracked(fn) }()
83+
// The timeout goroutine also sets the phase key so logs from fn()
84+
// are captured under this phase's key.
85+
go func() {
86+
SetGoroutinePhaseKey(phaseKey)
87+
defer ClearGoroutinePhaseKey()
88+
done <- fn()
89+
}()
8590
select {
8691
case err = <-done:
8792
<-phaseSemaphore
@@ -94,7 +99,7 @@ func RunWorkflowPhase(phaseKey string, step, total int, description, target stri
9499
}()
95100
}
96101
} else {
97-
err = runTracked(fn)
102+
err = fn()
98103
<-phaseSemaphore
99104
}
100105

0 commit comments

Comments
 (0)