From 125c15bcd09972d754284693f26857517ef9869c Mon Sep 17 00:00:00 2001 From: Abhishek Bhunia Date: Fri, 15 May 2026 07:51:44 -0700 Subject: [PATCH] Register tracing log hook before signal handling Signed-off-by: Abhishek Bhunia --- cmd/containerd/command/main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/containerd/command/main.go b/cmd/containerd/command/main.go index b3e360d3c2..684a6a8abc 100644 --- a/cmd/containerd/command/main.go +++ b/cmd/containerd/command/main.go @@ -163,6 +163,12 @@ can be used and modified as necessary as a custom configuration.` return err } + // Register the tracing hook as soon as config is available. Later startup + // steps may start goroutines that log, so avoid mutating hooks after hook + // reads may have begun. + tracingHook := tracing.NewLogrusHook(tracing.WithTraceIDField(config.Debug.LogTraceID)) + logrus.StandardLogger().AddHook(tracingHook) + // Make sure top-level directories are created early. if err := server.CreateTopLevelDirectories(config); err != nil { return err @@ -195,10 +201,6 @@ can be used and modified as necessary as a custom configuration.` log.G(ctx).WithError(w).Warn("cleanup temp mount") } - // Register logging hook for tracing - tracingHook := tracing.NewLogrusHook(tracing.WithTraceIDField(config.Debug.LogTraceID)) - logrus.StandardLogger().AddHook(tracingHook) - log.G(ctx).WithFields(log.Fields{ "version": version.Version, "revision": version.Revision,