making trace as an error when error occurs and fix the format

This commit is contained in:
yangzhouhan
2015-07-28 10:13:40 -07:00
parent a747bc19d9
commit a3dce46030
3 changed files with 21 additions and 8 deletions

View File

@ -163,7 +163,7 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
}
return toRPCErr(err)
}
if EnableTracing {
if c.traceInfo.tr != nil {
c.traceInfo.tr.LazyLog(&payload{sent: true, msg: args}, true)
}
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 {
continue
}
if EnableTracing {
if c.traceInfo.tr != nil {
c.traceInfo.tr.LazyLog(&payload{sent: false, msg: reply}, true)
}
t.CloseStream(stream, lastErr)

View File

@ -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) {
var traceInfo traceInfo
var (
traceInfo traceInfo
err error
)
if EnableTracing {
traceInfo.tr = trace.New("Recv."+methodFamily(srvn), srvn)
defer traceInfo.tr.Finish()
traceInfo.firstLine.client = 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}
for {
@ -276,7 +285,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
}
return
}
if EnableTracing {
if traceInfo.tr != nil {
traceInfo.tr.LazyLog(&payload{sent: false, msg: req}, true)
}
switch pf {
@ -314,7 +323,7 @@ func (s *Server) processUnaryRPC(t transport.ServerTransport, stream *transport.
}
}
t.WriteStatus(stream, statusCode, statusDesc)
if EnableTracing {
if traceInfo.tr != nil {
traceInfo.tr.LazyLog(&payload{sent: true, msg: reply}, true)
}
default:

View File

@ -282,9 +282,13 @@ type serverStream struct {
codec Codec
statusCode codes.Code
statusDesc string
tracing bool
mu sync.Mutex
traceInfo traceInfo
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
}
func (ss *serverStream) Context() context.Context {