Skip to content

Commit

Permalink
add comment about intention
Browse files Browse the repository at this point in the history
  • Loading branch information
prodion23 committed May 6, 2024
1 parent 104cd9d commit 5999ec5
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sdk/instrumentation/bodyattribute/bodyattribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func SetEncodedBodyAttribute(attrName string, body []byte, truncated bool, span

// Largely based on:
// https://github.com/jmacd/opentelemetry-go/blob/e8973b75b230246545cdae072a548c83877cba09/sdk/trace/span.go#L358-L375
// Intention here is to ensure that we capture the final parsed rune to prevent splitting multibyte rune in the middle
// If maxBytes - 4 is in middle of rune, that is okay, we still append since max rune size <= 4 so that means there is still
// a partial or full rune between maxBytes - 4 and the end.
// If we encounter a rune that extends beyond the end of our truncation length it will be dropped entirely
func truncateUTF8Bytes(b []byte, maxBytes int) []byte {
// We subtract 4 as that is the largest possible byte size for single rune
startIndex := maxBytes - 4
Expand Down

0 comments on commit 5999ec5

Please sign in to comment.