From 854414865d6f1d614fa58a4f97be4929425054e3 Mon Sep 17 00:00:00 2001 From: Stephan Renatus Date: Fri, 22 Dec 2023 09:35:52 +0100 Subject: [PATCH] runtime/logging: actually do not panic when rctx is missing Signed-off-by: Stephan Renatus --- runtime/logging.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/runtime/logging.go b/runtime/logging.go index a82f0e1f99..3c84d6efb9 100644 --- a/runtime/logging.go +++ b/runtime/logging.go @@ -24,8 +24,13 @@ type loggingPrintHook struct { func (h loggingPrintHook) Print(pctx print.Context, msg string) error { // NOTE(tsandall): if the request context is not present then do not panic, // just log the print message without the additional context. - rctx, _ := logging.FromContext(pctx.Context) - fields := rctx.Fields() + var fields map[string]any + rctx, ok := logging.FromContext(pctx.Context) + if ok { + fields = rctx.Fields() + } else { + fields = make(map[string]any, 1) + } fields["line"] = pctx.Location.String() h.logger.WithFields(fields).Info(msg) return nil