forked from TrueCloudLab/frostfs-s3-gw
[#501] Add the trace id to the logs of middlware
Signed-off-by: Roman Loginov <r.loginov@yadro.com>
This commit is contained in:
parent
76008d4ba1
commit
539dab8680
5 changed files with 11 additions and 28 deletions
|
@ -187,14 +187,21 @@ func Request(log *zap.Logger, settings RequestSettings) Func {
|
|||
|
||||
r = r.WithContext(treepool.SetRequestID(r.Context(), reqInfo.RequestID))
|
||||
|
||||
reqLogger := log.With(zap.String("request_id", reqInfo.RequestID))
|
||||
r = r.WithContext(SetReqLogger(r.Context(), reqLogger))
|
||||
fields := []zap.Field{zap.String("request_id", reqInfo.RequestID)}
|
||||
ctx, span := StartHTTPServerSpan(r, "REQUEST S3")
|
||||
if traceID := span.SpanContext().TraceID(); traceID.IsValid() {
|
||||
fields = append(fields, zap.String("trace_id", traceID.String()))
|
||||
}
|
||||
lw := &traceResponseWriter{ResponseWriter: w, ctx: ctx, span: span}
|
||||
|
||||
reqLogger := log.With(fields...)
|
||||
r = r.WithContext(SetReqLogger(ctx, reqLogger))
|
||||
|
||||
reqLogger.Info(logs.RequestStart, zap.String("host", r.Host),
|
||||
zap.String("remote_host", reqInfo.RemoteHost), zap.String("namespace", reqInfo.Namespace))
|
||||
|
||||
// continue execution
|
||||
h.ServeHTTP(w, r)
|
||||
h.ServeHTTP(lw, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue