Python: Fix non-ascii chars in span attributes#3894
Merged
TaoChenOSU merged 2 commits intomicrosoft:mainfrom Feb 12, 2026
Merged
Python: Fix non-ascii chars in span attributes#3894TaoChenOSU merged 2 commits intomicrosoft:mainfrom
TaoChenOSU merged 2 commits intomicrosoft:mainfrom
Conversation
Member
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
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=Falseparameter to JSON serialization calls in observability code for messages, system instructions, and tool definitions - Added
ensure_ascii=Falseparameter 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 |
giles17
approved these changes
Feb 12, 2026
eavanvalkenburg
approved these changes
Feb 12, 2026
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.
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:


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