1
0
Fork 0

Bring back TraceID and SpanID fields in access logs

Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
Romain 2025-01-15 16:26:08 +01:00 committed by GitHub
parent 020ab5f347
commit 4ce4bd7121
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 32 deletions

View file

@ -24,6 +24,7 @@ import (
traefiktls "github.com/traefik/traefik/v3/pkg/tls"
"github.com/traefik/traefik/v3/pkg/types"
"go.opentelemetry.io/contrib/bridges/otellogrus"
"go.opentelemetry.io/otel/trace"
)
type key string
@ -209,6 +210,12 @@ 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()
}
reqWithDataTable := req.WithContext(context.WithValue(req.Context(), DataTableKey, logDataTable))
core[RequestCount] = nextRequestCount()