Skip to content

Conversation

@TaoChenOSU
Copy link
Contributor

@TaoChenOSU TaoChenOSU commented Feb 12, 2026

Motivation and Context

Closes #3495

Description

If something contains non-ascii strings and when it's serialized to Json, the non-ascii chars will get escaped to unicodes that are not human readable.

This PR makes escaping non-ascii chars not enforced.

Before:
image
After:
image

Note that depending on the encoding used by monitor backend or console, texts may still be escaped.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@TaoChenOSU TaoChenOSU self-assigned this Feb 12, 2026
Copilot AI review requested due to automatic review settings February 12, 2026 20:12
@TaoChenOSU TaoChenOSU added the observability Issues related to observability or telemetry label Feb 12, 2026
@github-actions github-actions bot changed the title Fix non-ascii chars in span attributes Python: Fix non-ascii chars in span attributes Feb 12, 2026
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 12, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework
   _tools.py7558488%175–176, 306, 308, 326–328, 335, 353, 367, 379, 384, 386, 393, 430, 453–455, 504–506, 569, 591, 615–641, 676, 684, 925, 1187, 1244, 1248, 1327–1331, 1349, 1351–1352, 1464, 1468, 1518, 1520, 1536, 1538, 1602, 1629, 1686, 1754, 1933–1934, 1961, 1969, 1982, 1992–1993, 2028, 2084, 2116
   observability.py6188486%335, 337–339, 342–344, 349–350, 356–357, 363–364, 371, 373–375, 378–380, 385–386, 392–393, 399–400, 407, 676, 679, 687–688, 691–694, 696, 699–701, 704–705, 733, 735, 746–748, 750–753, 757, 765, 866, 868, 1017, 1019, 1023–1028, 1030, 1033–1037, 1039, 1151–1152, 1154, 1211–1212, 1347, 1401–1402, 1518–1520, 1579, 1749, 1903, 1905
TOTAL21258327684% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4106 225 💤 0 ❌ 0 🔥 1m 14s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where non-ASCII characters (Japanese, Chinese, Arabic, Korean, etc.) in OpenTelemetry span attributes were being escaped to Unicode sequences (e.g., \u4f01\u696d), making them unreadable in telemetry backends. The fix adds ensure_ascii=False to json.dumps() calls when serializing messages, system instructions, and tool definitions for telemetry.

Changes:

  • Added ensure_ascii=False parameter to JSON serialization calls in observability code for messages, system instructions, and tool definitions
  • Added ensure_ascii=False parameter to JSON serialization of tool arguments
  • Added comprehensive test coverage for non-ASCII character preservation across messages, system instructions, tool arguments, and tool results

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
python/packages/core/agent_framework/observability.py Added ensure_ascii=False to json.dumps calls for tool definitions (line 1560), input/output messages (line 1643), and system instructions (line 1649)
python/packages/core/agent_framework/_tools.py Added ensure_ascii=False to json.dumps call for tool arguments when not using Pydantic model (line 480)
python/packages/core/tests/core/test_observability.py Added 4 comprehensive tests covering non-ASCII character preservation in messages, system instructions, tool arguments, and tool results

@TaoChenOSU TaoChenOSU added this pull request to the merge queue Feb 12, 2026
Merged via the queue into microsoft:main with commit 1441fd9 Feb 12, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

observability Issues related to observability or telemetry python

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Japanese are exported as unicode when tracing via Open Telemetry

4 participants