Skip to content

Conversation

@RiviaAzusa
Copy link

@RiviaAzusa RiviaAzusa commented Sep 9, 2025

Add the ensure_ascii=False parameter to all json.dumps calls to ensure non-ASCII characters (such as Chinese) are not escaped into \uXXXX format.

Files to modify:

langfuse/_client/attributes.py: Core serialization functions
langfuse/_utils/request.py: API request data serialization
langfuse/_client/utils.py: Debug output formatting
langfuse/_task_manager/score_ingestion_consumer.py: Score processing serialization

Before Fix & After Fix:
CleanShot 2025-09-09 at 14 06 54@2x


Important

Add ensure_ascii=False to json.dumps calls to prevent non-ASCII character escaping in multiple files.

  • Behavior:
    • Add ensure_ascii=False to json.dumps in attributes.py for core serialization functions.
    • Add ensure_ascii=False to json.dumps in request.py for API request data serialization.
    • Add ensure_ascii=False to json.dumps in utils.py for debug output formatting.
    • Add ensure_ascii=False to json.dumps in score_ingestion_consumer.py for score processing serialization.

This description was created by Ellipsis for 843ed96. You can customize this summary. It will automatically update as commits are pushed.

Disclaimer: Experimental PR review

Greptile Summary

Updated On: 2025-09-09 06:09:40 UTC

This PR addresses a localization issue where non-ASCII characters (specifically Chinese characters) were being escaped to \uXXXX format in JSON serialization throughout the Langfuse Python SDK. The fix adds the ensure_ascii=False parameter to all json.dumps() calls across four key files to preserve Unicode characters in their original readable form.

The changes affect multiple serialization touchpoints:

  • langfuse/_client/attributes.py: Core serialization for OpenTelemetry span attributes
  • langfuse/_utils/request.py: API request data serialization sent to Langfuse servers
  • langfuse/_client/utils.py: Debug output formatting for span data
  • langfuse/_task_manager/score_ingestion_consumer.py: Score processing serialization and size calculations

All modified files use the existing EventSerializer class but now explicitly disable ASCII-only encoding. This ensures that when users trace LLM applications containing Chinese text (or other Unicode content), the data remains human-readable in the Langfuse UI, logs, and debug output. The change maintains JSON validity while improving the user experience for international developers.

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it only affects JSON output formatting without changing data structures or API compatibility
  • Score reflects that the changes are straightforward, well-targeted, and follow a consistent pattern across all affected files
  • No files require special attention as all changes follow the same simple pattern of adding the ensure_ascii=False parameter
在所有json.dumps调用中添加ensure_ascii=False参数,确保中文等非ASCII字符不会被转义为\uXXXX格式。

修改的文件:
- langfuse/_client/attributes.py: 核心序列化函数
- langfuse/_utils/request.py: API请求数据序列化
- langfuse/_client/utils.py: 调试输出格式化
- langfuse/_task_manager/score_ingestion_consumer.py: 分数处理序列化

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@CLAassistant
Copy link

CLAassistant commented Sep 9, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

4 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@nimarb
Copy link
Contributor

nimarb commented Sep 16, 2025

Hi @RiviaAzusa , thank you for the contribution! If possible, could you add at least one test for this behavior in order to ensure not running into this problem again? Thanks!

@gfx
Copy link

gfx commented Oct 3, 2025

I really want this PR is merged.

@chenyong
Copy link

chenyong commented Dec 17, 2025

I ran into the same problem, and Kimi K2 discovered the same patch. Any update on this?

And CJK full text search in traces list breaks due to this issue.

@johnmai-dev
Copy link

I really want this PR is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

6 participants