You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sanitizeArguments in pkg/telemetry/middleware.go shortens values with byte slices (valueStr[:100] + "..." and result[:200] + "..."). When a multi-byte character (CJK, accented letters, emoji) falls on the cut point, it is split and the string is no longer valid UTF-8. That string is stored in the gen_ai.tool.call.arguments span attribute. OTLP encodes attributes as proto3 string fields, which must be valid UTF-8, so the span fails to encode.
The metric-label path in the same file already truncates on a rune boundary (truncateLabelValue, #6279). This path was missed.
Steps to reproduce
A tool call whose argument value is 99 × a followed by 日本語. Passing that value through sanitizeArguments, then proto.Marshal on a commonpb.KeyValue holding the result (test in package telemetry, golang:1.25, main @ ae8b232):
value cut: got tail bytes "aaaa\xe6..."
sanitizeArguments returned invalid UTF-8 (len=105)
OTLP proto marshal of the span attribute fails: string field contains invalid UTF-8
Expected behavior
The truncated value is valid UTF-8 (aaaa...), and the attribute encodes.
Proposed fix
Back off to a rune boundary before slicing, e.g. a small truncateAtRuneBoundary(s, n) helper using utf8.RuneStart, used in both places. I'd add a multibyte row to TestHTTPMiddleware_SanitizeArguments. I plan to send the PR for this if that sounds good.
I used Claude Code to help find and check this, and I reviewed and ran the repro myself.
Activity