From 4e70b2aee2f068d49f4b4f257a129445d10fab86 Mon Sep 17 00:00:00 2001 From: Cian Craeye <38524989+craeyefish@users.noreply.github.com> Date: Tue, 15 Oct 2024 13:50:33 +0200 Subject: [PATCH] workflow: Add process name to error logs (#57) * workflow: Add process name to error logs * update fmt to expect string --- workflow.go | 4 ++-- workflow_internal_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/workflow.go b/workflow.go index ddbbcab..917aa45 100644 --- a/workflow.go +++ b/workflow.go @@ -215,7 +215,7 @@ func runOnce( // Exit cleanly if error returned is cancellation of context return err } else if err != nil { - logger.Error(ctx, fmt.Errorf("run error [role=%v]: %v", role, err)) + logger.Error(ctx, fmt.Errorf("run error [role=%s], [process=%s]: %v", role, processName, err)) // Return nil to try again return nil @@ -230,7 +230,7 @@ func runOnce( // and if the parent context was cancelled then that will exit safely. return nil } else if err != nil { - logger.Error(ctx, fmt.Errorf("run error [role=%v]: %v", role, err)) + logger.Error(ctx, fmt.Errorf("run error [role=%s], [process=%s]: %v", role, processName, err)) metrics.ProcessErrors.WithLabelValues(workflowName, processName).Inc() timer := clock.NewTimer(errBackOff) diff --git a/workflow_internal_test.go b/workflow_internal_test.go index 3b4a4f6..c869331 100644 --- a/workflow_internal_test.go +++ b/workflow_internal_test.go @@ -78,7 +78,7 @@ func Test_runOnce(t *testing.T) { time.Minute, ) require.Nil(t, err) - require.Contains(t, buf.String(), `"msg":"run error [role=role-1]: test error"`) + require.Contains(t, buf.String(), `"msg":"run error [role=role-1], [process=process-1]: test error"`) }) t.Run("Cancelled parent context during process execution retries and exits with context.Canceled ", func(t *testing.T) { @@ -149,7 +149,7 @@ func Test_runOnce(t *testing.T) { ) require.Nil(t, err) - require.Contains(t, buf.String(), `"msg":"run error [role=role-1]: test error`) + require.Contains(t, buf.String(), `"msg":"run error [role=role-1], [process=process-1]: test error`) }) t.Run("Updates process state", func(t *testing.T) {