Skip to content

Commit

Permalink
Merge pull request #160 from xmidt-org/denopink/patch/bug-repeating-c…
Browse files Browse the repository at this point in the history
…ontext

Patch SetLogger Bug: Shared logger among requests creates repeating logging context
  • Loading branch information
denopink authored Nov 11, 2022
2 parents 4e064fe + 595dca8 commit 29df941
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions basculehttp/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,23 @@ func SetLogger(logger *zap.Logger) alice.Constructor {
source = host
}

logger = logger.With(
l := logger.With(
zap.Reflect("request.Headers", sanitizeHeaders(r.Header)), //lgtm [go/clear-text-logging]
zap.String("request.URL", r.URL.EscapedPath()),
zap.String("request.method", r.Method),
zap.String("request.Method", r.Method),
zap.String("request.address", source),
zap.String("request.path", r.URL.Path),
zap.String("request.query", r.URL.RawQuery),
zap.String("request.tid", tid),
)
traceID, spanID, ok := candlelight.ExtractTraceInfo(r.Context())
if ok {
logger = logger.With(
l = l.With(
zap.String(candlelight.TraceIdLogKeyName, traceID),
zap.String(candlelight.SpanIDLogKeyName, spanID),
)
}
r = r.WithContext(sallust.With(r.Context(), logger))
r = r.WithContext(sallust.With(r.Context(), l))
delegate.ServeHTTP(w, r)
})
}
Expand Down

0 comments on commit 29df941

Please sign in to comment.