mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
feat: add span id
This commit is contained in:
parent
773e7eea79
commit
3b38ea311b
@ -5,9 +5,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
SpanID = "span_id"
|
||||
TraceID = "trace_id"
|
||||
)
|
||||
|
||||
func FSpanID(traceID string) zap.Field {
|
||||
return zap.String(SpanID, traceID)
|
||||
}
|
||||
|
||||
func FTraceID(traceID string) zap.Field {
|
||||
return zap.String(TraceID, traceID)
|
||||
}
|
||||
|
||||
@ -29,8 +29,8 @@ func WithServiceName(l *zap.Logger, name string) *zap.Logger {
|
||||
}
|
||||
|
||||
func WithTraceID(l *zap.Logger, ctx context.Context) *zap.Logger {
|
||||
if spanCtx := trace.SpanContextFromContext(ctx); spanCtx.IsValid() {
|
||||
l = With(l, FTraceID(spanCtx.TraceID().String()))
|
||||
if spanCtx := trace.SpanContextFromContext(ctx); spanCtx.IsValid() && spanCtx.IsSampled() {
|
||||
l = With(l, FTraceID(spanCtx.TraceID().String()), FSpanID(spanCtx.SpanID().String()))
|
||||
}
|
||||
return l
|
||||
}
|
||||
|
||||
@ -72,8 +72,9 @@ func TelemetryWithOptions(opts TelemetryOptions) Middleware {
|
||||
}
|
||||
|
||||
if labeler, ok := httplog.LabelerFromRequest(r); ok {
|
||||
if spanCtx := trace.SpanContextFromContext(r.Context()); spanCtx.IsValid() {
|
||||
if spanCtx := trace.SpanContextFromContext(r.Context()); spanCtx.IsValid() && spanCtx.IsSampled() {
|
||||
labeler.Add(log.FTraceID(spanCtx.TraceID().String()))
|
||||
labeler.Add(log.FSpanID(spanCtx.SpanID().String()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user