add spanid valuer

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

@ -52,11 +52,21 @@ func Timestamp(layout string) Valuer {
func TraceID() Valuer { func TraceID() Valuer {
return func(ctx context.Context) interface{} { return func(ctx context.Context) interface{} {
span := trace.SpanContextFromContext(ctx) span := trace.SpanContextFromContext(ctx)
var traceID string
if span.HasTraceID() { if span.HasTraceID() {
traceID = span.TraceID().String() return span.TraceID().String()
} }
return traceID return ""
}
}
// SpanID returns a spanid valuer.
func SpanID() Valuer {
return func(ctx context.Context) interface{} {
span := trace.SpanContextFromContext(ctx)
if span.HasSpanID() {
return span.SpanID().String()
}
return ""
} }
} }

Loading…
Cancel
Save