Skip to content

Add ensure_ascii=False to json.dumps() calls in telemetry tracer #37

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

Merged

Conversation

moritalous
Copy link
Contributor

Description

This PR adds ensure_ascii=False parameter to all json.dumps() calls in the telemetry tracer module. This change ensures proper handling of non-ASCII characters (such as Japanese, Chinese, or emoji) in telemetry data by preventing them from being escaped as \uXXXX sequences in JSON output. The modification improves readability of logs and telemetry data when working with international content.

Related Issues

No specific issue ticket, addressing as part of internationalization improvements.

Documentation PR

N/A - This is an internal implementation change that doesn't require documentation updates.

Type of Change

  • Bug fix

Testing

• [x] hatch fmt --linter
• [x] hatch fmt --formatter
• [x] hatch test --all

  • Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective or my feature works
  • [-] I have updated the documentation accordingly
  • [-] I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@moritalous moritalous requested a review from a team as a code owner May 18, 2025 13:06
@awsarron awsarron self-assigned this May 18, 2025
Copy link
Member

@awsarron awsarron left a comment

Choose a reason for hiding this comment

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

Thank you for the awesome PR @moritalous, really appreciate your contributions.

Can we add unit test coverage to https://github.com/strands-agents/sdk-python/blob/main/tests/strands/telemetry/test_tracer.py to guarantee that the characters are not escaped so that we don't regress on this in the future?

It might perhaps be nice, and make it easier to write a unit test case for, to have a function in https://github.com/strands-agents/sdk-python/blob/main/src/strands/telemetry/tracer.py (serialize() ?) that is called instead of calling json.dumps directly throughout the file. This new function could call json.dumps in one place, setting both ensure_ascii=False and cls=JSONEncoder.

@awsarron awsarron assigned moritalous and unassigned awsarron May 18, 2025
@moritalous
Copy link
Contributor Author

@awsarron
I've implemented the requested changes. The fix has been pushed to the repository. Please review when you have a chance.

@awsarron awsarron assigned awsarron and unassigned moritalous May 19, 2025
@awsarron awsarron enabled auto-merge (squash) May 23, 2025 02:59
@awsarron awsarron merged commit 1831bdb into strands-agents:main May 23, 2025
10 checks passed
@awsarron
Copy link
Member

Thank you for your contribution @moritalous ❤️

We'll get this deployed in the next patch version of strands-agents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants