-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
area:logsPart of OpenTelemetry logsPart of OpenTelemetry logsbugSomething isn't workingSomething isn't working
Milestone
Description
Similar to #5996, adding an attribute to a log record with the string value こんにちは
and an attribute value length of 3
set will result in the attribute value being こ
. It should be こんに
according to the OTel specification:
- 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,
Blocked by #5997 which implements an alternate approach that should be adopted to
opentelemetry-go/sdk/log/record.go
Lines 430 to 466 in 446ee38
// truncate returns a copy of str truncated to have a length of at most n | |
// characters. If the length of str is less than n, str itself is returned. | |
// | |
// The truncate of str ensures that no valid UTF-8 code point is split. The | |
// copy returned will be less than n if a characters straddles the length | |
// limit. | |
// | |
// No truncation is performed if n is less than zero. | |
func truncate(str string, n int) string { | |
if n < 0 { | |
return str | |
} | |
// cut returns a copy of the s truncated to not exceed a length of n. If | |
// invalid UTF-8 is encountered, s is returned with false. Otherwise, the | |
// truncated copy will be returned with true. | |
cut := func(s string) (string, bool) { | |
var i int | |
for i = 0; i < n; { | |
r, size := utf8.DecodeRuneInString(s[i:]) | |
if r == utf8.RuneError { | |
return s, false | |
} | |
if i+size > n { | |
break | |
} | |
i += size | |
} | |
return s[:i], true | |
} | |
cp, ok := cut(str) | |
if !ok { | |
cp, _ = cut(strings.ToValidUTF8(str, "")) | |
} | |
return cp | |
} |
Metadata
Metadata
Assignees
Labels
area:logsPart of OpenTelemetry logsPart of OpenTelemetry logsbugSomething isn't workingSomething isn't working