feat 链路追踪
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.hlsq.asia/mmorpg/service-common/discover"
|
||||
"git.hlsq.asia/mmorpg/service-common/log"
|
||||
"git.hlsq.asia/mmorpg/service-common/utils"
|
||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
"google.golang.org/grpc/status"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -21,12 +19,13 @@ type IService interface {
|
||||
}
|
||||
|
||||
type Base struct {
|
||||
Target string
|
||||
SID string
|
||||
Serve *grpc.Server
|
||||
EtcdTTL int64
|
||||
OnInit func(serve *grpc.Server)
|
||||
OnClose func()
|
||||
Target string
|
||||
ServiceName string
|
||||
SID string
|
||||
Serve *grpc.Server
|
||||
EtcdTTL int64
|
||||
OnInit func(serve *grpc.Server)
|
||||
OnClose func()
|
||||
|
||||
wg *sync.WaitGroup
|
||||
}
|
||||
@@ -48,17 +47,11 @@ func (s *Base) Init(addr string, port int32) {
|
||||
}
|
||||
|
||||
s.Serve = grpc.NewServer(
|
||||
grpc.UnaryInterceptor(
|
||||
func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
log.Errorf("service Panic: %v", r)
|
||||
err = status.Error(codes.Internal, fmt.Sprintf("%v", r))
|
||||
}
|
||||
}()
|
||||
return handler(ctx, req)
|
||||
},
|
||||
grpc.ChainUnaryInterceptor(
|
||||
s.RecoveryInterceptor,
|
||||
s.LoggingInterceptor,
|
||||
),
|
||||
grpc.StatsHandler(otelgrpc.NewServerHandler()),
|
||||
grpc.KeepaliveEnforcementPolicy(keepalive.EnforcementPolicy{
|
||||
MinTime: 20 * time.Second,
|
||||
PermitWithoutStream: true,
|
||||
|
||||
Reference in New Issue
Block a user