-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Truncate msg length in trace #1508
Conversation
4c5b0e6
to
e86c7c0
Compare
trace.go
Outdated
if l > len(x) { | ||
return x | ||
} | ||
return x[:l] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This truncation is incorrect if the string contains UTF-8 multibyte characters. It can produce invalid UTF-8 sequences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true, but is that a problem?
e86c7c0
to
83f7b21
Compare
83f7b21
to
e2f0dfb
Compare
If we have a large slice and then only hold on to a reference pointing to just the first
Presumably what we want here is an explicit copy instead. |
@irfansharif I added a commit to make a copy of the substring. PTAL. |
yup, that works. |
trace.go
Outdated
return fmt.Sprintf("sent: %v", p.msg) | ||
func newPayload(sent bool, msg interface{}) stringer { | ||
if sent { | ||
return stringer(truncate(fmt.Sprintf("sent: %v", msg), truncateSize)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For huge amounts of data and msgs that are natively Stringers
, it's probably best to call truncate(stringerMsg.String(), truncateSize)
inside fmt.Sprintf()
to avoid an allocation and copy of the data that will be removed anyway. But this is probably a pretty trivial savings.
The change in this PR doesn't work because it makes After this change, with trace on, even if Closing this PR because of that. |
fixes #695