fix: log startup errors to stderr and exit non-zero
schemas / vulnerabilities (pull_request) Successful in 1m49s
schemas / check (pull_request) Successful in 3m5s
schemas / check-release (pull_request) Successful in 3m45s
pre-commit / pre-commit (pull_request) Successful in 6m15s
schemas / build (pull_request) Successful in 5m51s
schemas / deploy-prod (pull_request) Has been skipped
schemas / vulnerabilities (pull_request) Successful in 1m49s
schemas / check (pull_request) Successful in 3m5s
schemas / check-release (pull_request) Successful in 3m45s
pre-commit / pre-commit (pull_request) Successful in 6m15s
schemas / build (pull_request) Successful in 5m51s
schemas / deploy-prod (pull_request) Has been skipped
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.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user