MCPcopy
hub / github.com/grafana/dskit / logWithRequest

Method logWithRequest

middleware/logging.go:59–76  ·  view source on GitHub ↗

logWithRequest information from the request and context as fields.

(r *http.Request)

Source from the content-addressed store, hash-verified

57
58// logWithRequest information from the request and context as fields.
59func (l Log) logWithRequest(r *http.Request) log.Logger {
60 localLog := l.Log
61 traceID, ok := tracing.ExtractSampledTraceID(r.Context())
62 if ok {
63 localLog = log.With(localLog, "trace_id", traceID)
64 } else if traceID != "" {
65 localLog = log.With(localLog, "trace_id_unsampled", traceID)
66 }
67
68 if l.SourceIPs != nil {
69 ips := l.SourceIPs.Get(r)
70 if ips != "" {
71 localLog = log.With(localLog, "sourceIPs", ips)
72 }
73 }
74
75 return user.LogWith(r.Context(), localLog)
76}
77
78// Wrap implements Middleware
79func (l Log) Wrap(next http.Handler) http.Handler {

Callers 1

WrapMethod · 0.95

Calls 5

ExtractSampledTraceIDFunction · 0.92
LogWithFunction · 0.92
WithMethod · 0.80
GetMethod · 0.65
ContextMethod · 0.45

Tested by

no test coverage detected