Skip to content

Commit 3214f76

Browse files
authored
Truncate payload trace string, and turn trace off by default (grpc#1509)
1 parent d46a365 commit 3214f76

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

trace.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
// EnableTracing controls whether to trace RPCs using the golang.org/x/net/trace package.
3333
// This should only be set before any RPCs are sent or received by this program.
34-
var EnableTracing = true
34+
var EnableTracing bool
3535

3636
// methodFamily returns the trace family for the given method.
3737
// It turns "/pkg.Service/GetFoo" into "pkg.Service".
@@ -76,6 +76,15 @@ func (f *firstLine) String() string {
7676
return line.String()
7777
}
7878

79+
const truncateSize = 100
80+
81+
func truncate(x string, l int) string {
82+
if l > len(x) {
83+
return x
84+
}
85+
return x[:l]
86+
}
87+
7988
// payload represents an RPC request or response payload.
8089
type payload struct {
8190
sent bool // whether this is an outgoing payload
@@ -85,9 +94,9 @@ type payload struct {
8594

8695
func (p payload) String() string {
8796
if p.sent {
88-
return fmt.Sprintf("sent: %v", p.msg)
97+
return truncate(fmt.Sprintf("sent: %v", p.msg), truncateSize)
8998
}
90-
return fmt.Sprintf("recv: %v", p.msg)
99+
return truncate(fmt.Sprintf("recv: %v", p.msg), truncateSize)
91100
}
92101

93102
type fmtStringer struct {

0 commit comments

Comments
 (0)