Repository navigation
fix(telemetry): truncate tool call arguments on a UTF-8 rune boundary - #7272
Merged
Merged
Conversation
sanitizeArguments cut values at 100 and the joined result at 200 bytes, which could split a multi-byte character and emit invalid UTF-8 in the gen_ai.tool.call.arguments span attribute. Signed-off-by: Alex <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7272 +/- ##
==========================================
- Coverage 81.88% 81.82% -0.06%
==========================================
Files 915 915
Lines 92769 92773 +4
==========================================
- Hits 75966 75916 -50
- Misses 16798 16852 +54
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ChrisJBurns
approved these changes
Nov 26, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sanitizeArgumentsshortens each tool-call argument value to 100 bytes and the joined string to 200 bytes with plain byte slicing. When the cut lands inside a multi-byte character (CJK, accented letters, emoji), thegen_ai.tool.call.argumentsspan attribute holds invalid UTF-8, and OTLP cannot encode it because proto3stringfields must be valid UTF-8.truncateUTF8helper that backs up to a rune boundary before cutting, the same approach as the existingtruncateLabelValue.Fixes #7264
Type of change
Test plan
go test ./pkg/telemetry, not the fulltask test)task test-e2e)task lint-fix)The new
TestHTTPMiddleware_SanitizeArguments_MultiByteTruncationrepeats世(3 bytes) so the 100-byte value limit and the 200-byte joined limit both land mid-character, and asserts the result is valid UTF-8 and ends in.... Both subtests fail without the fix.Does this introduce a user-facing change?
Yes. Spans for tool calls whose arguments contain multi-byte characters near the truncation limit now carry a valid
gen_ai.tool.call.argumentsattribute instead of failing to export.This change was prepared with the help of an AI coding assistant (Claude); the submitter is responsible for it.