mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
zap
This commit is contained in:
parent
a2b7c4da7e
commit
a3410beaec
@ -20,7 +20,7 @@ func rpcClientInterceptor(ctx context.Context, method string, req, resp interfac
|
|||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
return errs.ErrInternalServer.Wrap("call rpc request context is nil")
|
return errs.ErrInternalServer.Wrap("call rpc request context is nil")
|
||||||
}
|
}
|
||||||
log.ZInfo(ctx, "rpc client req", "req", "funcName", method, rpcString(req))
|
log.ZInfo(ctx, "rpc req", "req", "funcName", method, rpcString(req))
|
||||||
operationID, ok := ctx.Value(constant.OperationID).(string)
|
operationID, ok := ctx.Value(constant.OperationID).(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.ZWarn(ctx, "ctx missing operationID", errors.New("ctx missing operationID"))
|
log.ZWarn(ctx, "ctx missing operationID", errors.New("ctx missing operationID"))
|
||||||
@ -33,10 +33,10 @@ func rpcClientInterceptor(ctx context.Context, method string, req, resp interfac
|
|||||||
}
|
}
|
||||||
err = invoker(metadata.NewOutgoingContext(ctx, md), method, req, resp, cc, opts...)
|
err = invoker(metadata.NewOutgoingContext(ctx, md), method, req, resp, cc, opts...)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.ZInfo(ctx, "rpc client resp", "funcName", method, rpcString(resp))
|
log.ZInfo(ctx, "rpc resp", "funcName", method, rpcString(resp))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.ZError(ctx, "rpc result error:", err)
|
log.ZError(ctx, "rpc resp error:", err)
|
||||||
rpcErr, ok := err.(interface{ GRPCStatus() *status.Status })
|
rpcErr, ok := err.(interface{ GRPCStatus() *status.Status })
|
||||||
if !ok {
|
if !ok {
|
||||||
return errs.ErrInternalServer.Wrap(err.Error())
|
return errs.ErrInternalServer.Wrap(err.Error())
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
|
||||||
"math"
|
"math"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
)
|
)
|
||||||
@ -33,7 +32,6 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
funcName := info.FullMethod
|
funcName := info.FullMethod
|
||||||
log.ZInfo(ctx, "rpc req", "funcName", funcName, "req", rpcString(req))
|
|
||||||
md, ok := metadata.FromIncomingContext(ctx)
|
md, ok := metadata.FromIncomingContext(ctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, status.New(codes.InvalidArgument, "missing metadata").Err()
|
return nil, status.New(codes.InvalidArgument, "missing metadata").Err()
|
||||||
@ -49,15 +47,16 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
|||||||
}
|
}
|
||||||
ctx = context.WithValue(ctx, OperationID, operationID)
|
ctx = context.WithValue(ctx, OperationID, operationID)
|
||||||
ctx = context.WithValue(ctx, OpUserID, opUserID)
|
ctx = context.WithValue(ctx, OpUserID, opUserID)
|
||||||
|
log.ZInfo(ctx, "rpc req", "funcName", funcName, "req", rpcString(req))
|
||||||
resp, err = handler(ctx, req)
|
resp, err = handler(ctx, req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.ZInfo(ctx, "server handle rpc success", "funcName", funcName, "resp", rpcString(resp))
|
log.ZInfo(ctx, "rpc resp", "funcName", funcName, "resp", rpcString(resp))
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
unwrap := errs.Unwrap(err)
|
unwrap := errs.Unwrap(err)
|
||||||
codeErr := specialerror.ErrCode(unwrap)
|
codeErr := specialerror.ErrCode(unwrap)
|
||||||
if codeErr == nil {
|
if codeErr == nil {
|
||||||
log.ZError(ctx, "rpc InternalServer:", err, "req", req)
|
log.ZError(ctx, "rpc InternalServer error", err, "req", req)
|
||||||
codeErr = errs.ErrInternalServer
|
codeErr = errs.ErrInternalServer
|
||||||
}
|
}
|
||||||
code := codeErr.Code()
|
code := codeErr.Code()
|
||||||
@ -66,13 +65,13 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
|||||||
code = errs.ServerInternalError
|
code = errs.ServerInternalError
|
||||||
}
|
}
|
||||||
grpcStatus := status.New(codes.Code(code), codeErr.Msg())
|
grpcStatus := status.New(codes.Code(code), codeErr.Msg())
|
||||||
if unwrap != err {
|
//if unwrap != err {
|
||||||
stack := fmt.Sprintf("%+v", err)
|
// stack := fmt.Sprintf("%+v", err)
|
||||||
if details, err := grpcStatus.WithDetails(wrapperspb.String(stack)); err == nil {
|
// if details, err := grpcStatus.WithDetails(wrapperspb.String(stack)); err == nil {
|
||||||
grpcStatus = details
|
// grpcStatus = details
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
log.ZWarn(ctx, "rpc resp", err, "funcName", funcName)
|
log.ZWarn(ctx, "rpc resp", unwrap, "funcName", funcName)
|
||||||
return nil, grpcStatus.Err()
|
return nil, grpcStatus.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user