fix: opentelemetry traceid not correct (#1108)

This commit is contained in:
Kevin Wan
2021-10-01 22:44:37 +08:00
committed by GitHub
parent 295ec27e1b
commit ed15ca04f4
6 changed files with 24 additions and 18 deletions

View File

@@ -96,7 +96,10 @@ func WithContext(ctx context.Context) Logger {
func spanIdFromContext(ctx context.Context) string {
span := trace.SpanFromContext(ctx)
if span.IsRecording() {
return span.SpanContext().SpanID().String()
spanCtx := span.SpanContext()
if spanCtx.IsValid() {
return spanCtx.SpanID().String()
}
}
t, ok := ctx.Value(tracespec.TracingKey).(tracespec.Trace)
@@ -110,7 +113,10 @@ func spanIdFromContext(ctx context.Context) string {
func traceIdFromContext(ctx context.Context) string {
span := trace.SpanFromContext(ctx)
if span.IsRecording() {
return span.SpanContext().SpanID().String()
spanCtx := span.SpanContext()
if spanCtx.IsValid() {
return span.SpanContext().TraceID().String()
}
}
t, ok := ctx.Value(tracespec.TracingKey).(tracespec.Trace)