From d39280ec3389a701604febb221d3e563a9a2c62f Mon Sep 17 00:00:00 2001 From: Daenney Date: Fri, 17 Feb 2023 12:37:57 +0100 Subject: [PATCH] [bug] Pass context in logging middleware (#1514) This updates the middleware log.WithField calls that create new loggers to include the context the first time around. Without it the requestID does not get logged. Fixup from #1476 --- internal/middleware/logger.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/middleware/logger.go b/internal/middleware/logger.go index 6fd7ce2c8..723952eec 100644 --- a/internal/middleware/logger.go +++ b/internal/middleware/logger.go @@ -57,7 +57,8 @@ func Logger() gin.HandlerFunc { // Dump a stacktrace to error log callers := errors.GetCallers(3, 10) - log.WithField("stacktrace", callers).Error(err) + log.WithContext(c.Request.Context()). + WithField("stacktrace", callers).Error(err) } // NOTE: @@ -75,7 +76,8 @@ func Logger() gin.HandlerFunc { fields[5] = kv.Field{"path", path} // Create log entry with fields - l := log.WithFields(fields...) + l := log.WithContext(c.Request.Context()). + WithFields(fields...) // Default is info lvl := level.INFO