Add SpanID and TraceID accessLogs fields only when tracing is enabled

This commit is contained in:
Romain 2025-04-28 14:26:05 +02:00 committed by GitHub
parent b05ec75f98
commit 87b57406ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 89 additions and 23 deletions

View file

@ -212,8 +212,10 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http
if span := trace.SpanFromContext(req.Context()); span != nil {
spanContext := span.SpanContext()
logDataTable.Core[TraceID] = spanContext.TraceID().String()
logDataTable.Core[SpanID] = spanContext.SpanID().String()
if spanContext.HasTraceID() && spanContext.HasSpanID() {
logDataTable.Core[TraceID] = spanContext.TraceID().String()
logDataTable.Core[SpanID] = spanContext.SpanID().String()
}
}
reqWithDataTable := req.WithContext(context.WithValue(req.Context(), DataTableKey, logDataTable))