Skip to content

Commit

Permalink
runtime/logging: actually do not panic when rctx is missing
Browse files Browse the repository at this point in the history
Signed-off-by: Stephan Renatus <stephan@styra.com>
  • Loading branch information
srenatus authored and ashutosh-narkar committed Dec 22, 2023
1 parent fd96808 commit eb17a71
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions runtime/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eb17a71

Please sign in to comment.