diff --git a/call.go b/call.go index f0dec479..a6dad304 100644 --- a/call.go +++ b/call.go @@ -164,7 +164,11 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli return toRPCErr(err) } if EnableTracing { - c.traceInfo.tr.LazyLog(&fmtStringer{"sent: %v", []interface{}{payload{args}}}, true) + p := &payload{ + sent: true, + msg: args, + } + c.traceInfo.tr.LazyLog(p, true) } stream, err = sendRequest(ctx, cc.dopts.codec, callHdr, t, args, topts) if err != nil { @@ -183,7 +187,11 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli continue } if EnableTracing { - c.traceInfo.tr.LazyLog(&fmtStringer{"received: %v", []interface{}{payload{reply}}}, true) + p := &payload{ + sent: false, + msg: reply, + } + c.traceInfo.tr.LazyLog(p, true) } t.CloseStream(stream, lastErr) if lastErr != nil { diff --git a/stream.go b/stream.go index 348fe9a5..256d0f01 100644 --- a/stream.go +++ b/stream.go @@ -166,7 +166,11 @@ func (cs *clientStream) SendMsg(m interface{}) (err error) { if cs.tracing { cs.mu.Lock() if cs.traceInfo.tr != nil { - cs.traceInfo.tr.LazyLog(&fmtStringer{"sent: %v", []interface{}{payload{m}}}, true) + p := &payload{ + sent: true, + msg: m, + } + cs.traceInfo.tr.LazyLog(p, true) } cs.mu.Unlock() } @@ -190,7 +194,13 @@ func (cs *clientStream) RecvMsg(m interface{}) (err error) { if cs.tracing { cs.mu.Lock() if cs.traceInfo.tr != nil { - cs.traceInfo.tr.LazyLog(&fmtStringer{"received: %v", []interface{}{payload{m}}}, true) + if cs.traceInfo.tr != nil { + p := &payload{ + sent: false, + msg: m, + } + cs.traceInfo.tr.LazyLog(p, true) + } } cs.mu.Unlock() } diff --git a/trace.go b/trace.go index f8df478d..32c086cb 100644 --- a/trace.go +++ b/trace.go @@ -93,12 +93,17 @@ func (f *firstLine) String() string { // payload represents an RPC request or response payload. type payload struct { - m interface{} // e.g. a proto.Message + sent bool // whether this is a request or response + msg interface{} // e.g. a proto.Message // TODO(dsymonds): add stringifying info to codec, and limit how much we hold here? } func (p payload) String() string { - return fmt.Sprint(p.m) + if p.sent { + return fmt.Sprintf("sent: %v", p.msg) + } else { + return fmt.Sprintf("recv: %v", p.msg) + } } type fmtStringer struct {