making trace as an error when error occurs and fix the format
This commit is contained in:
4
call.go
4
call.go
@ -163,7 +163,7 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
|
|||||||
}
|
}
|
||||||
return toRPCErr(err)
|
return toRPCErr(err)
|
||||||
}
|
}
|
||||||
if EnableTracing {
|
if c.traceInfo.tr != nil {
|
||||||
c.traceInfo.tr.LazyLog(&payload{sent: true, msg: args}, true)
|
c.traceInfo.tr.LazyLog(&payload{sent: true, msg: args}, true)
|
||||||
}
|
}
|
||||||
stream, err = sendRequest(ctx, cc.dopts.codec, callHdr, t, args, topts)
|
stream, err = sendRequest(ctx, cc.dopts.codec, callHdr, t, args, topts)
|
||||||
@ -182,7 +182,7 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
|
|||||||
if _, ok := lastErr.(transport.ConnectionError); ok {
|
if _, ok := lastErr.(transport.ConnectionError); ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if EnableTracing {
|
if c.traceInfo.tr != nil {
|
||||||
c.traceInfo.tr.LazyLog(&payload{sent: false, msg: reply}, true)
|
c.traceInfo.tr.LazyLog(&payload{sent: false, msg: reply}, true)
|
||||||
}
|
}
|
||||||
t.CloseStream(stream, lastErr)
|
t.CloseStream(stream, lastErr)
|
||||||
|
15
server.go
15
server.go
@ -249,12 +249,21 @@ func (s *Server) sendResponse(t transport.ServerTransport, stream *transport.Str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.Stream, srv *service, md *MethodDesc, srvn string) {
|
func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.Stream, srv *service, md *MethodDesc, srvn string) {
|
||||||
var traceInfo traceInfo
|
var (
|
||||||
|
traceInfo traceInfo
|
||||||
|
err error
|
||||||
|
)
|
||||||
if EnableTracing {
|
if EnableTracing {
|
||||||
traceInfo.tr = trace.New("Recv."+methodFamily(srvn), srvn)
|
traceInfo.tr = trace.New("Recv."+methodFamily(srvn), srvn)
|
||||||
defer traceInfo.tr.Finish()
|
defer traceInfo.tr.Finish()
|
||||||
traceInfo.firstLine.client = false
|
traceInfo.firstLine.client = false
|
||||||
traceInfo.tr.LazyLog(&traceInfo.firstLine, false)
|
traceInfo.tr.LazyLog(&traceInfo.firstLine, false)
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
traceInfo.tr.LazyLog(&fmtStringer{"%v", []interface{}{err}}, true)
|
||||||
|
traceInfo.tr.SetError()
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
p := &parser{s: stream}
|
p := &parser{s: stream}
|
||||||
for {
|
for {
|
||||||
@ -276,7 +285,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if EnableTracing {
|
if traceInfo.tr != nil {
|
||||||
traceInfo.tr.LazyLog(&payload{sent: false, msg: req}, true)
|
traceInfo.tr.LazyLog(&payload{sent: false, msg: req}, true)
|
||||||
}
|
}
|
||||||
switch pf {
|
switch pf {
|
||||||
@ -314,7 +323,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.WriteStatus(stream, statusCode, statusDesc)
|
t.WriteStatus(stream, statusCode, statusDesc)
|
||||||
if EnableTracing {
|
if traceInfo.tr != nil {
|
||||||
traceInfo.tr.LazyLog(&payload{sent: true, msg: reply}, true)
|
traceInfo.tr.LazyLog(&payload{sent: true, msg: reply}, true)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -282,8 +282,12 @@ type serverStream struct {
|
|||||||
codec Codec
|
codec Codec
|
||||||
statusCode codes.Code
|
statusCode codes.Code
|
||||||
statusDesc string
|
statusDesc string
|
||||||
tracing bool
|
|
||||||
mu sync.Mutex
|
tracing bool // set to EnableTracing when the serverStream is created.
|
||||||
|
|
||||||
|
mu sync.Mutex // protects traceInfo
|
||||||
|
// traceInfo.tr is set when the serverStream is created (if EnableTracing is true),
|
||||||
|
// and is set to nil when the serverStream's finish method is called.
|
||||||
traceInfo traceInfo
|
traceInfo traceInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user