From ac9a33d214ecbe361946749e38eeba09031ac90b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Fri, 17 Apr 2026 17:52:31 +0200 Subject: [PATCH] test: truncate attribute string values using Unicode rune count (#8219) Add test cases to ensure correct behavior. From https://opentelemetry.io/docs/specs/otel/common/#attribute-limits: > set an attribute value length limit such that for each attribute value: > - if it is a string, if it exceeds that limit (counting any character in it as 1), SDKs MUST truncate that value, so that its length is at most equal to the limit, --- sdk/trace/span_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sdk/trace/span_test.go b/sdk/trace/span_test.go index eac0036d2..a6b0a6c7f 100644 --- a/sdk/trace/span_test.go +++ b/sdk/trace/span_test.go @@ -200,6 +200,27 @@ func TestTruncateAttr(t *testing.T) { attr: strSliceAttr, want: strSliceAttr, }, + { + // Multi-byte string: byte length (9) exceeds limit (5) but rune count (3) does not. + // Must not be truncated. + limit: 5, + attr: attribute.String(key, "日本語"), + want: attribute.String(key, "日本語"), + }, + { + // Multi-byte string: both byte length and rune count exceed limit. + // Must be truncated to limit runes. + limit: 2, + attr: attribute.String(key, "日本語"), + want: attribute.String(key, "日本"), + }, + { + // STRINGSLICE with multi-byte elements: byte lengths exceed limit but rune counts do not. + // Must not be truncated. + limit: 1, + attr: attribute.StringSlice(key, []string{"日", "本"}), + want: attribute.StringSlice(key, []string{"日", "本"}), + }, } for _, test := range tests {