Skip to content

fix(telemetry): truncate tool call arguments on a UTF-8 rune boundary - #7272

Merged
ChrisJBurns merged 1 commit into
stacklok:mainfrom
pcbeingused333:c5414-utf8-truncate
Nov 26, 2026
Merged

ChrisJBurns merged 1 commit into
stacklok:mainfrom
pcbeingused333:c5414-utf8-truncate

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Summary

sanitizeArguments shortens 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), the gen_ai.tool.call.arguments span attribute holds invalid UTF-8, and OTLP cannot encode it because proto3 string fields must be valid UTF-8.

  • Add a small truncateUTF8 helper that backs up to a rune boundary before cutting, the same approach as the existing truncateLabelValue.
  • Use it for both the per-value and the joined-result limit. Output for ASCII input is unchanged.

Fixes #7264

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (go test ./pkg/telemetry, not the full task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

The new TestHTTPMiddleware_SanitizeArguments_MultiByteTruncation repeats 世 (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.arguments attribute instead of failing to export.


This change was prepared with the help of an AI coding assistant (Claude); the submitter is responsible for it.

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

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.82%. Comparing base (44f7d63) to head (92a45ac).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisJBurns
ChrisJBurns merged commit 6f1c7a8 into stacklok:main Nov 26, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telemetry: sanitizeArguments cuts tool-call arguments mid-character, producing invalid UTF-8 span attributes

2 participants