diff --git a/docs/content/observability/access-logs.md b/docs/content/observability/access-logs.md index 4b5ce0b360..a8ccdeca4a 100644 --- a/docs/content/observability/access-logs.md +++ b/docs/content/observability/access-logs.md @@ -281,8 +281,10 @@ accessLog: | `TLSVersion` | The TLS version used by the connection (e.g. `1.2`) (if connection is TLS). | | `TLSCipher` | The TLS cipher used by the connection (e.g. `TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA`) (if connection is TLS) | | `TLSClientSubject` | The string representation of the TLS client certificate's Subject (e.g. `CN=username,O=organization`) | - | `TraceId` | A consistent identifier for tracking requests across services, including upstream ones managed by Traefik, shown as a 32-hex digit string | - | `SpanId` | A unique identifier for Traefik’s root span (EntryPoint) within a request trace, formatted as a 16-hex digit string. | + | `TraceId` | (Deprecated) A consistent identifier for tracking requests across services, including upstream ones managed by Traefik, shown as a 32-hex digit string | + | `SpanId` | (Deprecated) A unique identifier for Traefik’s root span (EntryPoint) within a request trace, formatted as a 16-hex digit string. | + | `trace_id` | OTel-conformant trace identifier for tracking requests across services, including upstream ones managed by Traefik, shown as a 32-hex digit string | + | `span_id` | OTel-conformant span identifier for Traefik’s root span (EntryPoint) within a request trace, formatted as a 16-hex digit string. | ## Log Rotation diff --git a/pkg/middlewares/accesslog/logdata.go b/pkg/middlewares/accesslog/logdata.go index 451588b8a2..c9010fdd61 100644 --- a/pkg/middlewares/accesslog/logdata.go +++ b/pkg/middlewares/accesslog/logdata.go @@ -78,10 +78,15 @@ const ( // TLSClientSubject is the string representation of the TLS client certificate's Subject. TLSClientSubject = "TLSClientSubject" - // TraceID is the consistent identifier for tracking requests across services, including upstream ones managed by Traefik, shown as a 32-hex digit string. + // Deprecated: TraceID is the consistent identifier for tracking requests across services, including upstream ones managed by Traefik, shown as a 32-hex digit string. TraceID = "TraceId" - // SpanID is the unique identifier for Traefik’s root span (EntryPoint) within a request trace, formatted as a 16-hex digit string. + // Deprecated: SpanID is the unique identifier for Traefik’s root span (EntryPoint) within a request trace, formatted as a 16-hex digit string. SpanID = "SpanId" + + // OTelTraceID is the OTel-conformant log attribute for the trace identifier. + OTelTraceID = "trace_id" + // OTelSpanID is the OTel-conformant log attribute for the span identifier. + OTelSpanID = "span_id" ) // These are written out in the default case when no config is provided to specify keys of interest. @@ -126,6 +131,8 @@ func init() { allCoreKeys[TLSVersion] = struct{}{} allCoreKeys[TLSCipher] = struct{}{} allCoreKeys[TLSClientSubject] = struct{}{} + allCoreKeys[OTelTraceID] = struct{}{} + allCoreKeys[OTelSpanID] = struct{}{} } // CoreLogData holds the fields computed from the request/response. diff --git a/pkg/middlewares/accesslog/logger.go b/pkg/middlewares/accesslog/logger.go index fd6c9a686e..239d0708d0 100644 --- a/pkg/middlewares/accesslog/logger.go +++ b/pkg/middlewares/accesslog/logger.go @@ -207,6 +207,8 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http if spanContext.HasTraceID() && spanContext.HasSpanID() { logDataTable.Core[TraceID] = spanContext.TraceID().String() logDataTable.Core[SpanID] = spanContext.SpanID().String() + logDataTable.Core[OTelTraceID] = spanContext.TraceID().String() + logDataTable.Core[OTelSpanID] = spanContext.SpanID().String() } } diff --git a/pkg/middlewares/accesslog/logger_test.go b/pkg/middlewares/accesslog/logger_test.go index 2ccbffb660..78bf2ebe68 100644 --- a/pkg/middlewares/accesslog/logger_test.go +++ b/pkg/middlewares/accesslog/logger_test.go @@ -558,6 +558,8 @@ func TestLoggerJSON(t *testing.T) { "StartUTC": assertNotEmpty(), TraceID: assertString("01000000000000000000000000000000"), SpanID: assertString("0100000000000000"), + OTelTraceID: assertString("01000000000000000000000000000000"), + OTelSpanID: assertString("0100000000000000"), }, }, {