Skip to content

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

Done

Description

@1AbdullahButt

Bug description

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

  1. added
    needs-triage
    on Nov 24, 2026
  2. removed
    needs-triage
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions