Skip to content

Commit

Permalink
[bug] Pass context in logging middleware (#1514)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
daenney committed Feb 17, 2023
1 parent 1ca5c62 commit d39280e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit d39280e

Please sign in to comment.