1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00

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,
This commit is contained in:
Robert Pająk
2026-04-17 17:52:31 +02:00
committed by GitHub
parent dead3c1767
commit ac9a33d214
+21
View File
@@ -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 {