mirror of
https://github.com/traefik/traefik.git
synced 2026-05-05 04:16:25 +02:00
Add OTel-conformant trace context attributes to access logs
This commit is contained in:
parent
6d6374d499
commit
d7cc334238
@ -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
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -558,6 +558,8 @@ func TestLoggerJSON(t *testing.T) {
|
||||
"StartUTC": assertNotEmpty(),
|
||||
TraceID: assertString("01000000000000000000000000000000"),
|
||||
SpanID: assertString("0100000000000000"),
|
||||
OTelTraceID: assertString("01000000000000000000000000000000"),
|
||||
OTelSpanID: assertString("0100000000000000"),
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user