-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Python: Fix non-ascii chars in span attributes #3894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python: Fix non-ascii chars in span attributes #3894
Conversation
Python Test Coverage Report •
Python Unit Test Overview
|
|||||||||||||||||||||||||||||||||||
There was a problem hiding this 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=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 |
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