From 5d4ae201d0da1fdff8ffbe70547bc86ce92362e8 Mon Sep 17 00:00:00 2001 From: maizige <37949155+wsx864321@users.noreply.github.com> Date: Sat, 27 Aug 2022 18:55:40 +0800 Subject: [PATCH] Fix/del server interceptor duplicate copy md 20220827 (#2309) * fix:grpc server interceptor duplicate copy MD * modify wrong comments --- core/trace/tracer.go | 2 +- zrpc/internal/serverinterceptors/tracinginterceptor.go | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/core/trace/tracer.go b/core/trace/tracer.go index 8d5fed62..1e3ce0f5 100644 --- a/core/trace/tracer.go +++ b/core/trace/tracer.go @@ -38,7 +38,7 @@ func (s *metadataSupplier) Keys() []string { return out } -// Inject injects the metadata into ctx. +// Inject injects cross-cutting concerns from the ctx into the metadata. func Inject(ctx context.Context, p propagation.TextMapPropagator, metadata *metadata.MD) { p.Inject(ctx, &metadataSupplier{ metadata: metadata, diff --git a/zrpc/internal/serverinterceptors/tracinginterceptor.go b/zrpc/internal/serverinterceptors/tracinginterceptor.go index 1b2821de..788ca4cb 100644 --- a/zrpc/internal/serverinterceptors/tracinginterceptor.go +++ b/zrpc/internal/serverinterceptors/tracinginterceptor.go @@ -93,11 +93,8 @@ func (w *serverStream) SendMsg(m interface{}) error { } func startSpan(ctx context.Context, method string) (context.Context, trace.Span) { - var md metadata.MD - requestMetadata, ok := metadata.FromIncomingContext(ctx) - if ok { - md = requestMetadata.Copy() - } else { + md, ok := metadata.FromIncomingContext(ctx) + if !ok { md = metadata.MD{} } bags, spanCtx := ztrace.Extract(ctx, otel.GetTextMapPropagator(), &md)