Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log attributes are truncated by number of bytes not number of characters #6004

Closed
MrAlias opened this issue Nov 25, 2024 · 0 comments · Fixed by #6032
Closed

Log attributes are truncated by number of bytes not number of characters #6004

MrAlias opened this issue Nov 25, 2024 · 0 comments · Fixed by #6032
Labels
area:logs Part of OpenTelemetry logs bug Something isn't working
Milestone

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Nov 25, 2024

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

// 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
}
if it is accepted.

@MrAlias MrAlias added the bug Something isn't working label Nov 25, 2024
@MrAlias MrAlias added this to the v1.33.0 milestone Nov 25, 2024
@pellared pellared added the area:logs Part of OpenTelemetry logs label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:logs Part of OpenTelemetry logs bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants