add default tracer valuer

pull/1001/head
longXboy 4 years ago committed by longxboy
parent 4860f42637
commit 08d4db2c0c
  1. 14
      log/value.go

@ -6,6 +6,8 @@ import (
"strconv"
"strings"
"time"
"go.opentelemetry.io/otel/trace"
)
var (
@ -46,6 +48,18 @@ func Timestamp(layout string) Valuer {
}
}
// TraceID returns a traceid valuer.
func TraceID() Valuer {
return func(ctx context.Context) interface{} {
span := trace.SpanContextFromContext(ctx)
var traceID string
if span.HasTraceID() {
traceID = span.TraceID().String()
}
return traceID
}
}
func bindValues(ctx context.Context, keyvals []interface{}) {
for i := 1; i < len(keyvals); i += 2 {
if v, ok := keyvals[i].(Valuer); ok {

Loading…
Cancel
Save