From 3291de787af033ea9f902ffdb2a574a406c2c752 Mon Sep 17 00:00:00 2001 From: Ziqi Zhao Date: Mon, 10 Oct 2022 13:38:40 +0800 Subject: [PATCH] fix for failed test-race Signed-off-by: Ziqi Zhao --- sdk/trace/span.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/sdk/trace/span.go b/sdk/trace/span.go index 9760923f702..4443eb755ac 100644 --- a/sdk/trace/span.go +++ b/sdk/trace/span.go @@ -313,26 +313,13 @@ func truncateAttr(limit int, attr attribute.KeyValue) attribute.KeyValue { return attr.Key.String(safeTruncate(v, limit)) } case attribute.STRINGSLICE: - // Do no mutate the original, make a copy. - trucated := attr.Key.StringSlice(attr.Value.AsStringSlice()) - // Do not do this. - // - // v := trucated.Value.AsStringSlice() - // cp := make([]string, len(v)) - // /* Copy and truncate values to cp ... */ - // 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() + v := attr.Value.AsStringSlice() for i := range v { if len(v[i]) > limit { v[i] = safeTruncate(v[i], limit) } } - return trucated + return attr.Key.StringSlice(v) } return attr }