Add SpanID and TraceID accessLogs fields only when tracing is enabled
This commit is contained in:
parent
b05ec75f98
commit
87b57406ff
2 changed files with 89 additions and 23 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue