From 381816a66e1f59f196cee5a8f14c4249dc144789 Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Mon, 25 May 2026 22:34:57 +0200 Subject: [PATCH] fix: log startup errors to stderr and exit non-zero When start() returns an error, main() logged it via the slog logger and returned normally (exit 0), so a crash-looping pod showed as "Completed" with no error in the logs: start() defers the OTel SDK shutdown, tearing down the log exporter before main() logs, so with LOG_FORMAT=otel the record never reaches Alloy. Also write the error to stderr (always captured by `kubectl logs`) and os.Exit(1) so the container is correctly reported as failed. --- cmd/service/service.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/service/service.go b/cmd/service/service.go index 0cf29bb..8457a5a 100644 --- a/cmd/service/service.go +++ b/cmd/service/service.go @@ -66,6 +66,13 @@ func main() { cli, ); err != nil { logger.With("error", err).Error("process error") + // start() defers the OTel SDK shutdown, so by the time we get here the + // log exporter may already be torn down and the line above never + // reaches Alloy. Write to stderr too so startup failures are always + // visible in `kubectl logs`, and exit non-zero so the container is + // reported as failed (CrashLoopBackOff) instead of "Completed". + fmt.Fprintf(os.Stderr, "fatal: process error: %v\n", err) + os.Exit(1) } }