diff --git a/pkg/server/grpc/grpc.go b/pkg/server/grpc/grpc.go index 29774485eb..926b6068aa 100644 --- a/pkg/server/grpc/grpc.go +++ b/pkg/server/grpc/grpc.go @@ -59,8 +59,7 @@ func New(logger log.Logger, reg prometheus.Registerer, tracer opentracing.Tracer return status.Errorf(codes.Internal, "%s", p) } - grpcOpts := []grpc.ServerOption{} - grpcOpts = append(grpcOpts, + grpcOpts := []grpc.ServerOption{ grpc.MaxSendMsgSize(math.MaxInt32), grpc_middleware.WithUnaryServerChain( met.UnaryServerInterceptor(), @@ -72,7 +71,7 @@ func New(logger log.Logger, reg prometheus.Registerer, tracer opentracing.Tracer tracing.StreamServerInterceptor(tracer), grpc_recovery.StreamServerInterceptor(grpc_recovery.WithRecoveryHandler(grpcPanicRecoveryHandler)), ), - ) + } if options.tlsConfig != nil { grpcOpts = append(grpcOpts, grpc.Creds(credentials.NewTLS(options.tlsConfig))) diff --git a/pkg/tracing/grpc.go b/pkg/tracing/grpc.go index ee13810ca7..91c861ebb3 100644 --- a/pkg/tracing/grpc.go +++ b/pkg/tracing/grpc.go @@ -21,17 +21,21 @@ func StreamClientInterceptor(tracer opentracing.Tracer) grpc.StreamClientInterce // UnaryServerInterceptor returns a new unary server interceptor for OpenTracing and injects given tracer. func UnaryServerInterceptor(tracer opentracing.Tracer) grpc.UnaryServerInterceptor { + interceptor := grpc_opentracing.UnaryServerInterceptor(grpc_opentracing.WithTracer(tracer)) return func(parentCtx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { - return grpc_opentracing.UnaryServerInterceptor(grpc_opentracing.WithTracer(tracer))(ContextWithTracer(parentCtx, tracer), req, info, handler) + // Add our own tracer. + return interceptor(ContextWithTracer(parentCtx, tracer), req, info, handler) } } // StreamServerInterceptor returns a new streaming server interceptor for OpenTracing and injects given tracer. func StreamServerInterceptor(tracer opentracing.Tracer) grpc.StreamServerInterceptor { + interceptor := grpc_opentracing.StreamServerInterceptor(grpc_opentracing.WithTracer(tracer)) return func(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error { + // Add our own tracer. wrappedStream := grpc_middleware.WrapServerStream(stream) wrappedStream.WrappedContext = ContextWithTracer(stream.Context(), tracer) - return grpc_opentracing.StreamServerInterceptor(grpc_opentracing.WithTracer(tracer))(srv, wrappedStream, info, handler) + return interceptor(srv, wrappedStream, info, handler) } }