Parcourir la source

调整项目生成的模板

dcsunny il y a 4 ans
Parent
commit
f9e99750fc

+ 4 - 4
Makefile

@@ -3,16 +3,16 @@
 docker-dev:
 	@rm -rf ./bin/server && \
 	go mod download && \
-	go build -tags netgo -o ./bin/ -ldflags "-X main.Name={kratos-layout} -X main.namespace=01d2876e-0384-4638-af85-3b5009ff16a5 -X main.group=we-mp" ./... && \
-	docker build -t {kratos-layout} .
+	CGO_ENABLED=0 go build -o ./bin/ -ldflags "-X main.Name={kratos-layout} -X main.namespace=01d2876e-0384-4638-af85-3b5009ff16a5 -X main.group=we-mp" ./... && \
+	docker build -t {kratos-layout}-dev .
 
 #线上环境使用
 .PHONY: docker-pro
 docker-pro:
 	@rm -rf ./bin/server && \
 	go mod download && \
-	go build -tags netgo -o ./bin/ -ldflags "-X main.Name={kratos-layout} -X main.namespace=c8bf0196-4a26-4b07-b09e-9f49b7e1a241 -X main.group=we-mp" ./... && \
-	docker build -t {kratos-layout} .
+	CGO_ENABLED=0 go build -o ./bin/ -ldflags "-X main.Name={kratos-layout} -X main.namespace=c8bf0196-4a26-4b07-b09e-9f49b7e1a241 -X main.group=we-mp" ./... && \
+	docker build -t {kratos-layout}-pro .
 
 #本机环境使用
 .PHONY: docker-mac #指令重命名

+ 2 - 0
api/helloworld/v1/greeter_http.pb.go

@@ -11,6 +11,7 @@ import (
 	http "github.com/go-kratos/kratos/v2/transport/http"
 	binding "github.com/go-kratos/kratos/v2/transport/http/binding"
 	ioutil "io/ioutil"
+	time "time"
 )
 
 // This is a compile-time assertion to ensure that this generated file
@@ -18,6 +19,7 @@ import (
 var _ = new(context.Context)
 var _ = binding.EncodeURL
 var _ = ioutil.Discard
+var _ = new(time.Time)
 var _ = new(reply.SuccessReply)
 var _ = new(base.Html)
 

+ 16 - 6
cmd/server/main.go

@@ -35,9 +35,18 @@ var (
 )
 
 func init() {
-	flag.StringVar(&flagconf, "conf", "../../configs", "config path, eg: -conf config.yaml")
-	//flag.StringVar(&group, "group", "", "service group, eg: -group test")
-	//flag.StringVar(&namespace, "namespace", "c8bf0196-4a26-4b07-b09e-9f49b7e1a241", "service namespace, eg: -group test")
+	var _group string
+	var _namespace string
+	flag.StringVar(&flagconf, "conf", "", "config path, eg: -conf config.yaml")
+	flag.StringVar(&_group, "group", "", "service group, eg: -group test")
+	flag.StringVar(&_namespace, "namespace", "c8bf0196-4a26-4b07-b09e-9f49b7e1a241", "service namespace, eg: -group test")
+	flag.Parse()
+	if _group != "" {
+		group = _group
+	}
+	if _namespace != "" {
+		namespace = _namespace
+	}
 }
 
 func newApp(ctx context.Context, logger log.Logger, r *registry.Registry, hs *http.Server, gs *grpc.Server) *kratos.App {
@@ -66,12 +75,12 @@ func newApp(ctx context.Context, logger log.Logger, r *registry.Registry, hs *ht
 
 func main() {
 	ctx := context.Background()
-	flag.Parse()
 	logger := log.NewStdLogger(os.Stdout)
 	logger = log.With(logger, "caller", log.Caller(4), "ts", log.DefaultTimestamp)
 	var confSource config.Source
-	if group == "" {
+	if flagconf != "" {
 		confSource = file.NewSource(flagconf)
+
 	} else {
 		confSource = nacosConfig.NewSource("http://config.airdropin.com:80",
 			namespace,
@@ -109,10 +118,11 @@ func main() {
 	if err != nil {
 		panic(err)
 	}
-	app, err := initApp(ctx, &bc, logger)
+	app, cleanup, err := initApp(ctx, &bc, logger)
 	if err != nil {
 		panic(err)
 	}
+	defer cleanup()
 	// start and wait for stop signal
 	if err = app.Run(); err != nil {
 		panic(err)

+ 1 - 1
cmd/server/wire.go

@@ -17,6 +17,6 @@ import (
 )
 
 // initApp init kratos application.
-func initApp(context.Context, *conf.Bootstrap, log.Logger) (*kratos.App, error) {
+func initApp(context.Context, *conf.Bootstrap, log.Logger) (*kratos.App, func(), error) {
 	panic(wire.Build(server.ProviderSet, data.ProviderSet, service.ProviderSet, newApp))
 }

+ 6 - 4
cmd/server/wire_gen.go

@@ -18,16 +18,18 @@ import (
 // Injectors from wire.go:
 
 // initApp init kratos application.
-func initApp(contextContext context.Context, bootstrap *conf.Bootstrap, logger log.Logger) (*kratos.App, error) {
+func initApp(contextContext context.Context, bootstrap *conf.Bootstrap, logger log.Logger) (*kratos.App, func(), error) {
 	registry := server.NewRegistrar(bootstrap)
 	client := data.NewRedis(bootstrap)
-	dataData, err := data.NewData(bootstrap, client, logger)
+	dataData, cleanup, err := data.NewData(bootstrap, client, logger)
 	if err != nil {
-		return nil, err
+		return nil, nil, err
 	}
 	greeterServer := service.NewGreeterService(logger, dataData)
 	httpServer := server.NewHTTPServer(bootstrap, logger, greeterServer)
 	grpcServer := server.NewGRPCServer(bootstrap, logger)
 	app := newApp(contextContext, logger, registry, httpServer, grpcServer)
-	return app, nil
+	return app, func() {
+		cleanup()
+	}, nil
 }

+ 1 - 0
go.mod

@@ -18,6 +18,7 @@ require (
 	github.com/kr/text v0.2.0 // indirect
 	github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
 	github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
+	go.opentelemetry.io/otel v1.0.0-RC1
 	golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
 	google.golang.org/genproto v0.0.0-20210629200056-84d6f6074151
 	google.golang.org/grpc v1.39.0

+ 5 - 0
go.sum

@@ -204,6 +204,7 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykE
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
 github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a h1:pa8hGb/2YqsZKovtsgrwcDH1RZhVbTKCjLp47XpqCDs=
 github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
+github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@@ -229,7 +230,11 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
 github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
 go.opentelemetry.io/otel v1.0.0-RC1 h1:4CeoX93DNTWt8awGK9JmNXzF9j7TyOu9upscEdtcdXc=
 go.opentelemetry.io/otel v1.0.0-RC1/go.mod h1:x9tRa9HK4hSSq7jf2TKbqFbtt58/TGk0f9XiEYISI1I=
+go.opentelemetry.io/otel/exporters/jaeger v1.0.0-RC1 h1:tVhw2BMSAk248rhdeirOe9hlXKwGHDvVtF7P8F+H2DU=
+go.opentelemetry.io/otel/exporters/jaeger v1.0.0-RC1/go.mod h1:FXJnjGCoTQL6nQ8OpFJ0JI1DrdOvMoVx49ic0Hg4+D4=
+go.opentelemetry.io/otel/oteltest v1.0.0-RC1 h1:G685iP3XiskCwk/z0eIabL55XUl2gk0cljhGk9sB0Yk=
 go.opentelemetry.io/otel/oteltest v1.0.0-RC1/go.mod h1:+eoIG0gdEOaPNftuy1YScLr1Gb4mL/9lpDkZ0JjMRq4=
+go.opentelemetry.io/otel/sdk v1.0.0-RC1 h1:Sy2VLOOg24bipyC29PhuMXYNJrLsxkie8hyI7kUlG9Q=
 go.opentelemetry.io/otel/sdk v1.0.0-RC1/go.mod h1:kj6yPn7Pgt5ByRuwesbaWcRLA+V7BSDg3Hf8xRvsvf8=
 go.opentelemetry.io/otel/trace v1.0.0-RC1 h1:jrjqKJZEibFrDz+umEASeU3LvdVyWKlnTh7XEfwrT58=
 go.opentelemetry.io/otel/trace v1.0.0-RC1/go.mod h1:86UHmyHWFEtWjfWPSbu0+d0Pf9Q6e1U+3ViBOc+NXAg=

+ 149 - 65
internal/conf/conf.pb.go

@@ -26,9 +26,10 @@ type Bootstrap struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Server *Server `protobuf:"bytes,1,opt,name=server,proto3" json:"server"`
-	Data   *Data   `protobuf:"bytes,2,opt,name=data,proto3" json:"data"`
-	Jwt    *JWT    `protobuf:"bytes,3,opt,name=jwt,proto3" json:"jwt"`
+	Server    *Server    `protobuf:"bytes,1,opt,name=server,proto3" json:"server"`
+	Data      *Data      `protobuf:"bytes,2,opt,name=data,proto3" json:"data"`
+	Jwt       *JWT       `protobuf:"bytes,3,opt,name=jwt,proto3" json:"jwt"`
+	TraceConf *TraceConf `protobuf:"bytes,4,opt,name=traceConf,proto3" json:"traceConf"`
 }
 
 func (x *Bootstrap) Reset() {
@@ -84,6 +85,68 @@ func (x *Bootstrap) GetJwt() *JWT {
 	return nil
 }
 
+func (x *Bootstrap) GetTraceConf() *TraceConf {
+	if x != nil {
+		return x.TraceConf
+	}
+	return nil
+}
+
+type TraceConf struct {
+	state         protoimpl.MessageState
+	sizeCache     protoimpl.SizeCache
+	unknownFields protoimpl.UnknownFields
+
+	Endpoint string `protobuf:"bytes,1,opt,name=endpoint,proto3" json:"endpoint"`
+	Env      string `protobuf:"bytes,2,opt,name=env,proto3" json:"env"`
+}
+
+func (x *TraceConf) Reset() {
+	*x = TraceConf{}
+	if protoimpl.UnsafeEnabled {
+		mi := &file_conf_proto_msgTypes[1]
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		ms.StoreMessageInfo(mi)
+	}
+}
+
+func (x *TraceConf) String() string {
+	return protoimpl.X.MessageStringOf(x)
+}
+
+func (*TraceConf) ProtoMessage() {}
+
+func (x *TraceConf) ProtoReflect() protoreflect.Message {
+	mi := &file_conf_proto_msgTypes[1]
+	if protoimpl.UnsafeEnabled && x != nil {
+		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+		if ms.LoadMessageInfo() == nil {
+			ms.StoreMessageInfo(mi)
+		}
+		return ms
+	}
+	return mi.MessageOf(x)
+}
+
+// Deprecated: Use TraceConf.ProtoReflect.Descriptor instead.
+func (*TraceConf) Descriptor() ([]byte, []int) {
+	return file_conf_proto_rawDescGZIP(), []int{1}
+}
+
+func (x *TraceConf) GetEndpoint() string {
+	if x != nil {
+		return x.Endpoint
+	}
+	return ""
+}
+
+func (x *TraceConf) GetEnv() string {
+	if x != nil {
+		return x.Env
+	}
+	return ""
+}
+
 type Server struct {
 	state         protoimpl.MessageState
 	sizeCache     protoimpl.SizeCache
@@ -97,7 +160,7 @@ type Server struct {
 func (x *Server) Reset() {
 	*x = Server{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_conf_proto_msgTypes[1]
+		mi := &file_conf_proto_msgTypes[2]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -110,7 +173,7 @@ func (x *Server) String() string {
 func (*Server) ProtoMessage() {}
 
 func (x *Server) ProtoReflect() protoreflect.Message {
-	mi := &file_conf_proto_msgTypes[1]
+	mi := &file_conf_proto_msgTypes[2]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -123,7 +186,7 @@ func (x *Server) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Server.ProtoReflect.Descriptor instead.
 func (*Server) Descriptor() ([]byte, []int) {
-	return file_conf_proto_rawDescGZIP(), []int{1}
+	return file_conf_proto_rawDescGZIP(), []int{2}
 }
 
 func (x *Server) GetHttp() *Server_HTTP {
@@ -159,7 +222,7 @@ type Data struct {
 func (x *Data) Reset() {
 	*x = Data{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_conf_proto_msgTypes[2]
+		mi := &file_conf_proto_msgTypes[3]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -172,7 +235,7 @@ func (x *Data) String() string {
 func (*Data) ProtoMessage() {}
 
 func (x *Data) ProtoReflect() protoreflect.Message {
-	mi := &file_conf_proto_msgTypes[2]
+	mi := &file_conf_proto_msgTypes[3]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -185,7 +248,7 @@ func (x *Data) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Data.ProtoReflect.Descriptor instead.
 func (*Data) Descriptor() ([]byte, []int) {
-	return file_conf_proto_rawDescGZIP(), []int{2}
+	return file_conf_proto_rawDescGZIP(), []int{3}
 }
 
 func (x *Data) GetDatabase() *Data_Database {
@@ -214,7 +277,7 @@ type JWT struct {
 func (x *JWT) Reset() {
 	*x = JWT{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_conf_proto_msgTypes[3]
+		mi := &file_conf_proto_msgTypes[4]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -227,7 +290,7 @@ func (x *JWT) String() string {
 func (*JWT) ProtoMessage() {}
 
 func (x *JWT) ProtoReflect() protoreflect.Message {
-	mi := &file_conf_proto_msgTypes[3]
+	mi := &file_conf_proto_msgTypes[4]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -240,7 +303,7 @@ func (x *JWT) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use JWT.ProtoReflect.Descriptor instead.
 func (*JWT) Descriptor() ([]byte, []int) {
-	return file_conf_proto_rawDescGZIP(), []int{3}
+	return file_conf_proto_rawDescGZIP(), []int{4}
 }
 
 func (x *JWT) GetSecret() string {
@@ -270,7 +333,7 @@ type Server_HTTP struct {
 func (x *Server_HTTP) Reset() {
 	*x = Server_HTTP{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_conf_proto_msgTypes[4]
+		mi := &file_conf_proto_msgTypes[5]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -283,7 +346,7 @@ func (x *Server_HTTP) String() string {
 func (*Server_HTTP) ProtoMessage() {}
 
 func (x *Server_HTTP) ProtoReflect() protoreflect.Message {
-	mi := &file_conf_proto_msgTypes[4]
+	mi := &file_conf_proto_msgTypes[5]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -296,7 +359,7 @@ func (x *Server_HTTP) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Server_HTTP.ProtoReflect.Descriptor instead.
 func (*Server_HTTP) Descriptor() ([]byte, []int) {
-	return file_conf_proto_rawDescGZIP(), []int{1, 0}
+	return file_conf_proto_rawDescGZIP(), []int{2, 0}
 }
 
 func (x *Server_HTTP) GetNetwork() string {
@@ -333,7 +396,7 @@ type Server_GRPC struct {
 func (x *Server_GRPC) Reset() {
 	*x = Server_GRPC{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_conf_proto_msgTypes[5]
+		mi := &file_conf_proto_msgTypes[6]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -346,7 +409,7 @@ func (x *Server_GRPC) String() string {
 func (*Server_GRPC) ProtoMessage() {}
 
 func (x *Server_GRPC) ProtoReflect() protoreflect.Message {
-	mi := &file_conf_proto_msgTypes[5]
+	mi := &file_conf_proto_msgTypes[6]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -359,7 +422,7 @@ func (x *Server_GRPC) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Server_GRPC.ProtoReflect.Descriptor instead.
 func (*Server_GRPC) Descriptor() ([]byte, []int) {
-	return file_conf_proto_rawDescGZIP(), []int{1, 1}
+	return file_conf_proto_rawDescGZIP(), []int{2, 1}
 }
 
 func (x *Server_GRPC) GetNetwork() string {
@@ -395,7 +458,7 @@ type Server_Registrar struct {
 func (x *Server_Registrar) Reset() {
 	*x = Server_Registrar{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_conf_proto_msgTypes[6]
+		mi := &file_conf_proto_msgTypes[7]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -408,7 +471,7 @@ func (x *Server_Registrar) String() string {
 func (*Server_Registrar) ProtoMessage() {}
 
 func (x *Server_Registrar) ProtoReflect() protoreflect.Message {
-	mi := &file_conf_proto_msgTypes[6]
+	mi := &file_conf_proto_msgTypes[7]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -421,7 +484,7 @@ func (x *Server_Registrar) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Server_Registrar.ProtoReflect.Descriptor instead.
 func (*Server_Registrar) Descriptor() ([]byte, []int) {
-	return file_conf_proto_rawDescGZIP(), []int{1, 2}
+	return file_conf_proto_rawDescGZIP(), []int{2, 2}
 }
 
 func (x *Server_Registrar) GetNamespace() string {
@@ -452,7 +515,7 @@ type Data_Database struct {
 func (x *Data_Database) Reset() {
 	*x = Data_Database{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_conf_proto_msgTypes[7]
+		mi := &file_conf_proto_msgTypes[8]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -465,7 +528,7 @@ func (x *Data_Database) String() string {
 func (*Data_Database) ProtoMessage() {}
 
 func (x *Data_Database) ProtoReflect() protoreflect.Message {
-	mi := &file_conf_proto_msgTypes[7]
+	mi := &file_conf_proto_msgTypes[8]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -478,7 +541,7 @@ func (x *Data_Database) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Data_Database.ProtoReflect.Descriptor instead.
 func (*Data_Database) Descriptor() ([]byte, []int) {
-	return file_conf_proto_rawDescGZIP(), []int{2, 0}
+	return file_conf_proto_rawDescGZIP(), []int{3, 0}
 }
 
 func (x *Data_Database) GetDriver() string {
@@ -527,7 +590,7 @@ type Data_Redis struct {
 func (x *Data_Redis) Reset() {
 	*x = Data_Redis{}
 	if protoimpl.UnsafeEnabled {
-		mi := &file_conf_proto_msgTypes[8]
+		mi := &file_conf_proto_msgTypes[9]
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		ms.StoreMessageInfo(mi)
 	}
@@ -540,7 +603,7 @@ func (x *Data_Redis) String() string {
 func (*Data_Redis) ProtoMessage() {}
 
 func (x *Data_Redis) ProtoReflect() protoreflect.Message {
-	mi := &file_conf_proto_msgTypes[8]
+	mi := &file_conf_proto_msgTypes[9]
 	if protoimpl.UnsafeEnabled && x != nil {
 		ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
 		if ms.LoadMessageInfo() == nil {
@@ -553,7 +616,7 @@ func (x *Data_Redis) ProtoReflect() protoreflect.Message {
 
 // Deprecated: Use Data_Redis.ProtoReflect.Descriptor instead.
 func (*Data_Redis) Descriptor() ([]byte, []int) {
-	return file_conf_proto_rawDescGZIP(), []int{2, 1}
+	return file_conf_proto_rawDescGZIP(), []int{3, 1}
 }
 
 func (x *Data_Redis) GetNetwork() string {
@@ -618,7 +681,7 @@ var file_conf_proto_rawDesc = []byte{
 	0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x6b, 0x72,
 	0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65,
 	0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69,
-	0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x80, 0x01, 0x0a, 0x09, 0x42, 0x6f, 0x6f,
+	0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xb5, 0x01, 0x0a, 0x09, 0x42, 0x6f, 0x6f,
 	0x74, 0x73, 0x74, 0x72, 0x61, 0x70, 0x12, 0x2a, 0x0a, 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72,
 	0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e,
 	0x61, 0x70, 0x69, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x06, 0x73, 0x65, 0x72, 0x76,
@@ -626,7 +689,14 @@ var file_conf_proto_rawDesc = []byte{
 	0x32, 0x10, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x44, 0x61,
 	0x74, 0x61, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x21, 0x0a, 0x03, 0x6a, 0x77, 0x74, 0x18,
 	0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61,
-	0x70, 0x69, 0x2e, 0x4a, 0x57, 0x54, 0x52, 0x03, 0x6a, 0x77, 0x74, 0x22, 0xb5, 0x03, 0x0a, 0x06,
+	0x70, 0x69, 0x2e, 0x4a, 0x57, 0x54, 0x52, 0x03, 0x6a, 0x77, 0x74, 0x12, 0x33, 0x0a, 0x09, 0x74,
+	0x72, 0x61, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15,
+	0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x72, 0x61, 0x63,
+	0x65, 0x43, 0x6f, 0x6e, 0x66, 0x52, 0x09, 0x74, 0x72, 0x61, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66,
+	0x22, 0x39, 0x0a, 0x09, 0x54, 0x72, 0x61, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x12, 0x1a, 0x0a,
+	0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
+	0x08, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x6e, 0x76,
+	0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x65, 0x6e, 0x76, 0x22, 0xb5, 0x03, 0x0a, 0x06,
 	0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x2b, 0x0a, 0x04, 0x68, 0x74, 0x74, 0x70, 0x18, 0x01,
 	0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x6b, 0x72, 0x61, 0x74, 0x6f, 0x73, 0x2e, 0x61, 0x70,
 	0x69, 0x2e, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x04, 0x68,
@@ -712,38 +782,40 @@ func file_conf_proto_rawDescGZIP() []byte {
 	return file_conf_proto_rawDescData
 }
 
-var file_conf_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
+var file_conf_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
 var file_conf_proto_goTypes = []interface{}{
 	(*Bootstrap)(nil),           // 0: kratos.api.Bootstrap
-	(*Server)(nil),              // 1: kratos.api.Server
-	(*Data)(nil),                // 2: kratos.api.Data
-	(*JWT)(nil),                 // 3: kratos.api.JWT
-	(*Server_HTTP)(nil),         // 4: kratos.api.Server.HTTP
-	(*Server_GRPC)(nil),         // 5: kratos.api.Server.GRPC
-	(*Server_Registrar)(nil),    // 6: kratos.api.Server.Registrar
-	(*Data_Database)(nil),       // 7: kratos.api.Data.Database
-	(*Data_Redis)(nil),          // 8: kratos.api.Data.Redis
-	(*durationpb.Duration)(nil), // 9: google.protobuf.Duration
+	(*TraceConf)(nil),           // 1: kratos.api.TraceConf
+	(*Server)(nil),              // 2: kratos.api.Server
+	(*Data)(nil),                // 3: kratos.api.Data
+	(*JWT)(nil),                 // 4: kratos.api.JWT
+	(*Server_HTTP)(nil),         // 5: kratos.api.Server.HTTP
+	(*Server_GRPC)(nil),         // 6: kratos.api.Server.GRPC
+	(*Server_Registrar)(nil),    // 7: kratos.api.Server.Registrar
+	(*Data_Database)(nil),       // 8: kratos.api.Data.Database
+	(*Data_Redis)(nil),          // 9: kratos.api.Data.Redis
+	(*durationpb.Duration)(nil), // 10: google.protobuf.Duration
 }
 var file_conf_proto_depIdxs = []int32{
-	1,  // 0: kratos.api.Bootstrap.server:type_name -> kratos.api.Server
-	2,  // 1: kratos.api.Bootstrap.data:type_name -> kratos.api.Data
-	3,  // 2: kratos.api.Bootstrap.jwt:type_name -> kratos.api.JWT
-	4,  // 3: kratos.api.Server.http:type_name -> kratos.api.Server.HTTP
-	5,  // 4: kratos.api.Server.grpc:type_name -> kratos.api.Server.GRPC
-	6,  // 5: kratos.api.Server.registrar:type_name -> kratos.api.Server.Registrar
-	7,  // 6: kratos.api.Data.database:type_name -> kratos.api.Data.Database
-	8,  // 7: kratos.api.Data.redis:type_name -> kratos.api.Data.Redis
-	9,  // 8: kratos.api.Server.HTTP.timeout:type_name -> google.protobuf.Duration
-	9,  // 9: kratos.api.Server.GRPC.timeout:type_name -> google.protobuf.Duration
-	9,  // 10: kratos.api.Data.Redis.dial_timeout:type_name -> google.protobuf.Duration
-	9,  // 11: kratos.api.Data.Redis.read_timeout:type_name -> google.protobuf.Duration
-	9,  // 12: kratos.api.Data.Redis.write_timeout:type_name -> google.protobuf.Duration
-	13, // [13:13] is the sub-list for method output_type
-	13, // [13:13] is the sub-list for method input_type
-	13, // [13:13] is the sub-list for extension type_name
-	13, // [13:13] is the sub-list for extension extendee
-	0,  // [0:13] is the sub-list for field type_name
+	2,  // 0: kratos.api.Bootstrap.server:type_name -> kratos.api.Server
+	3,  // 1: kratos.api.Bootstrap.data:type_name -> kratos.api.Data
+	4,  // 2: kratos.api.Bootstrap.jwt:type_name -> kratos.api.JWT
+	1,  // 3: kratos.api.Bootstrap.traceConf:type_name -> kratos.api.TraceConf
+	5,  // 4: kratos.api.Server.http:type_name -> kratos.api.Server.HTTP
+	6,  // 5: kratos.api.Server.grpc:type_name -> kratos.api.Server.GRPC
+	7,  // 6: kratos.api.Server.registrar:type_name -> kratos.api.Server.Registrar
+	8,  // 7: kratos.api.Data.database:type_name -> kratos.api.Data.Database
+	9,  // 8: kratos.api.Data.redis:type_name -> kratos.api.Data.Redis
+	10, // 9: kratos.api.Server.HTTP.timeout:type_name -> google.protobuf.Duration
+	10, // 10: kratos.api.Server.GRPC.timeout:type_name -> google.protobuf.Duration
+	10, // 11: kratos.api.Data.Redis.dial_timeout:type_name -> google.protobuf.Duration
+	10, // 12: kratos.api.Data.Redis.read_timeout:type_name -> google.protobuf.Duration
+	10, // 13: kratos.api.Data.Redis.write_timeout:type_name -> google.protobuf.Duration
+	14, // [14:14] is the sub-list for method output_type
+	14, // [14:14] is the sub-list for method input_type
+	14, // [14:14] is the sub-list for extension type_name
+	14, // [14:14] is the sub-list for extension extendee
+	0,  // [0:14] is the sub-list for field type_name
 }
 
 func init() { file_conf_proto_init() }
@@ -765,7 +837,7 @@ func file_conf_proto_init() {
 			}
 		}
 		file_conf_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*Server); i {
+			switch v := v.(*TraceConf); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -777,7 +849,7 @@ func file_conf_proto_init() {
 			}
 		}
 		file_conf_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*Data); i {
+			switch v := v.(*Server); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -789,7 +861,7 @@ func file_conf_proto_init() {
 			}
 		}
 		file_conf_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*JWT); i {
+			switch v := v.(*Data); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -801,7 +873,7 @@ func file_conf_proto_init() {
 			}
 		}
 		file_conf_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*Server_HTTP); i {
+			switch v := v.(*JWT); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -813,7 +885,7 @@ func file_conf_proto_init() {
 			}
 		}
 		file_conf_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*Server_GRPC); i {
+			switch v := v.(*Server_HTTP); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -825,7 +897,7 @@ func file_conf_proto_init() {
 			}
 		}
 		file_conf_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*Server_Registrar); i {
+			switch v := v.(*Server_GRPC); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -837,7 +909,7 @@ func file_conf_proto_init() {
 			}
 		}
 		file_conf_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
-			switch v := v.(*Data_Database); i {
+			switch v := v.(*Server_Registrar); i {
 			case 0:
 				return &v.state
 			case 1:
@@ -849,6 +921,18 @@ func file_conf_proto_init() {
 			}
 		}
 		file_conf_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
+			switch v := v.(*Data_Database); i {
+			case 0:
+				return &v.state
+			case 1:
+				return &v.sizeCache
+			case 2:
+				return &v.unknownFields
+			default:
+				return nil
+			}
+		}
+		file_conf_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
 			switch v := v.(*Data_Redis); i {
 			case 0:
 				return &v.state
@@ -867,7 +951,7 @@ func file_conf_proto_init() {
 			GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
 			RawDescriptor: file_conf_proto_rawDesc,
 			NumEnums:      0,
-			NumMessages:   9,
+			NumMessages:   10,
 			NumExtensions: 0,
 			NumServices:   0,
 		},

+ 6 - 0
internal/conf/conf.proto

@@ -9,6 +9,12 @@ message Bootstrap {
   Server server = 1;
   Data data = 2;
   JWT jwt = 3;
+  TraceConf traceConf = 4;
+}
+
+message TraceConf {
+  string endpoint = 1;
+  string env = 2;
 }
 
 message Server {

+ 13 - 3
internal/data/data.go

@@ -19,7 +19,9 @@ type Data struct {
 }
 
 // NewData .
-func NewData(c *conf.Bootstrap, rdb *redis.Client, logger log.Logger) (*Data, error) {
+func NewData(c *conf.Bootstrap, rdb *redis.Client, logger log.Logger) (*Data, func(), error) {
+	cleanup := func() {
+	}
 	data := &Data{
 		log: log.NewHelper(log.With(logger, "module", "data/data")),
 	}
@@ -27,13 +29,21 @@ func NewData(c *conf.Bootstrap, rdb *redis.Client, logger log.Logger) (*Data, er
 	if c.Data.Database != nil {
 		data.Mysql, err = models.NewMysql(c.Data.Database.Source, logger)
 		if err != nil {
-			return nil, err
+			return nil, cleanup, err
 		}
 		data.Mysql.XDB.SetMaxIdleConns(int(c.Data.Database.MaxIdleConns))
 		data.Mysql.XDB.SetMaxOpenConns(int(c.Data.Database.MaxOpenConns))
 	}
 	data.rdb = rdb
-	return data, nil
+	cleanup = func() {
+		if data.XDB != nil {
+			data.XDB.Close()
+		}
+		if data.rdb != nil {
+			data.rdb.Close()
+		}
+	}
+	return data, cleanup, nil
 }
 
 func NewRedis(c *conf.Bootstrap) *redis.Client {

+ 25 - 5
internal/server/grpc.go

@@ -3,22 +3,42 @@ package server
 import (
 	middleware2 "git.ikuban.com/server/kratos-utils/http/middleware"
 	"git.ikuban.com/server/kratos-utils/http/middleware/logging"
+	"git.ikuban.com/server/we-protobuf/client"
+	"git.ikuban.com/server/we-protobuf/middleware/trace"
 	"github.com/go-kratos/kratos-layout/internal/conf"
 	"github.com/go-kratos/kratos/v2/log"
 	"github.com/go-kratos/kratos/v2/middleware"
 	"github.com/go-kratos/kratos/v2/middleware/recovery"
+	"github.com/go-kratos/kratos/v2/middleware/tracing"
 	"github.com/go-kratos/kratos/v2/transport/grpc"
+	"go.opentelemetry.io/otel/propagation"
+	grpc2 "google.golang.org/grpc"
 )
 
 // NewGRPCServer new a gRPC server.
 func NewGRPCServer(c *conf.Bootstrap, logger log.Logger) *grpc.Server {
+	tp, err := trace.TracerProvider(c.TraceConf.Endpoint, "{kratos-layout}", c.TraceConf.Env)
+	chain := []middleware.Middleware{
+		recovery.Recovery(),
+		logging.Server(logger),
+		middleware2.GrpcValue,
+	}
+
+	if err == nil && tp != nil {
+		chain = append(chain, tracing.Server(
+			tracing.WithTracerProvider(tp),
+			tracing.WithPropagator(
+				propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}),
+			),
+		))
+	}
 	var opts = []grpc.ServerOption{
 		grpc.Middleware(
-			middleware.Chain(
-				recovery.Recovery(),
-				logging.Server(logger),
-				middleware2.GrpcValue,
-			),
+			chain...,
+		),
+		grpc.Options(
+			grpc2.MaxRecvMsgSize(client.ReceiveMsgSize),
+			grpc2.MaxSendMsgSize(client.ReceiveMsgSize),
 		),
 	}
 	if c.Server.Grpc.Network != "" {

+ 20 - 4
internal/server/http.go

@@ -3,7 +3,11 @@ package server
 import (
 	http2 "net/http"
 
+	"github.com/go-kratos/kratos/v2/middleware/tracing"
+	"go.opentelemetry.io/otel/propagation"
+
 	"git.ikuban.com/server/kratos-utils/http/middleware/logging"
+	"git.ikuban.com/server/we-protobuf/middleware/trace"
 	v1 "github.com/go-kratos/kratos-layout/api/helloworld/v1"
 	"github.com/go-kratos/kratos-layout/internal/conf"
 	"github.com/go-kratos/kratos/v2/log"
@@ -24,12 +28,24 @@ func NewHTTPServer(c *conf.Bootstrap, logger log.Logger, s1 v1.GreeterServer) *h
 	if c.Server.Http.Timeout != nil {
 		opts = append(opts, http.Timeout(c.Server.Http.Timeout.AsDuration()))
 	}
+
+	tp, err := trace.TracerProvider(c.TraceConf.Endpoint, "{kratos-layout}", c.TraceConf.Env)
+	chain := []middleware.Middleware{
+		recovery.Recovery(),
+		logging.Server(logger),
+	}
+	if err == nil && tp != nil {
+		chain = append(chain, tracing.Server(
+			tracing.WithTracerProvider(tp),
+			tracing.WithPropagator(
+				propagation.NewCompositeTextMapPropagator(propagation.Baggage{}, propagation.TraceContext{}),
+			),
+		))
+	}
 	opts = append(opts, http.Middleware(
-		middleware.Chain(
-			recovery.Recovery(),
-			logging.Server(logger),
-		),
+		middleware.Chain(chain...),
 	))
+
 	srv := http.NewServer(opts...)
 	v1.RegisterGreeterHTTPServer(srv, s1)
 	srv.HandleFunc("/ping", func(w http2.ResponseWriter, r *http2.Request) {