Skip to content

Commit

Permalink
Update truncateAttr string slice update comment
Browse files Browse the repository at this point in the history
  • Loading branch information
MrAlias committed Feb 25, 2022
1 parent f81b753 commit 6c89ecb
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions sdk/trace/span.go
Expand Up @@ -306,10 +306,17 @@ func truncateAttr(limit int, attr attribute.KeyValue) attribute.KeyValue {
case attribute.STRINGSLICE:
// Do no mutate the original, make a copy.
trucated := attr.Key.StringSlice(attr.Value.AsStringSlice())
// Copying the underlying []string and then passing back as a new
// value with attribute.StringSliceValue will copy the data twice.
// Instead, make the copy with attribute.StringSliceValue and update
// the underlying slice data.
// Do not do this.
//
// v := trucated.Value.AsStringSlice()
// cp := make([]string, len(v))
// /* Truncate cp values ... */
// trucated.Value = attribute.StringSliceValue(cp)
//
// Copying the []string and then assigning it back as a new value with
// attribute.StringSliceValue will copy the data twice. Instead, we
// already made a copy above that only this function owns, update the
// underlying slice data of our copy.
v := trucated.Value.AsStringSlice()
for i := range v {
if len(v[i]) > limit {
Expand Down

0 comments on commit 6c89ecb

Please sign in to comment.