Skip to content

fix: Ensure tags values are strings #4459

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

szokeasaurusrex
Copy link
Member

@szokeasaurusrex szokeasaurusrex commented Jun 12, 2025

Tag value handling was updated to ensure compliance with the Sentry spec.

  • In sentry_sdk/scope.py, Scope.set_tag() was modified to convert values using safe_str(value). Scope.set_tags() was refactored to iterate and call self.set_tag() for each item, ensuring consistent conversion.
  • In sentry_sdk/tracing.py, Span.set_tag() was updated to use safe_str(value).

Comprehensive tests were added:

  • In tests/test_scope.py, new tests cover Scope.set_tag() and Scope.set_tags() conversion and error handling.
  • A new file, tests/tracing/test_span_tags.py, was created to test Span and Transaction tag conversion.
  • In tests/test_api.py, tests were added for API-level set_tag() and set_tags().

These changes ensure all tag values are strings, meeting Sentry spec requirements and improving compatibility with external tools like Sentry CLI.

Fixes #4391

@szokeasaurusrex szokeasaurusrex self-assigned this Jun 12, 2025
Copy link

codecov bot commented Jun 12, 2025

❌ 327 Tests Failed:

Tests completed Failed Passed Skipped
24929 327 24602 5790
View the top 3 failed test(s) by shortest run time
tests.test_scope::test_with_use_isolation_scope_data
Stack Traces | 0.001s run time
tests/test_scope.py:513: in test_with_use_isolation_scope_data
    assert isolation_scope_in._tags == {"before_custom_isolation_scope": 1}
E   AssertionError: assert {'before_custom_isolation_scope': '1'} == {'before_custom_isolation_scope': 1}
E     
E     Differing items:
E     {'before_custom_isolation_scope': '1'} != {'before_custom_isolation_scope': 1}
E     
E     Full diff:
E       {
E     -     'before_custom_isolation_scope': 1,
E     +     'before_custom_isolation_scope': '1',
E     ?                                      + +
E       }
tests.test_scope::test_with_use_scope_data
Stack Traces | 0.001s run time
tests/test_scope.py:708: in test_with_use_scope_data
    assert isolation_scope_in._tags == {"before_isolation_scope": 1}
E   AssertionError: assert {'before_isolation_scope': '1'} == {'before_isolation_scope': 1}
E     Differing items:
E     {'before_isolation_scope': '1'} != {'before_isolation_scope': 1}
E     Full diff:
E     - {'before_isolation_scope': 1}
E     + {'before_isolation_scope': '1'}
E     ?                            + +
tests.test_scope::test_with_use_scope_data
Stack Traces | 0.001s run time
tests/test_scope.py:708: in test_with_use_scope_data
    assert isolation_scope_in._tags == {"before_isolation_scope": 1}
E   AssertionError: assert {'before_isolation_scope': '1'} == {'before_isolation_scope': 1}
E     
E     Differing items:
E     {'before_isolation_scope': '1'} != {'before_isolation_scope': 1}
E     
E     Full diff:
E       {
E     -     'before_isolation_scope': 1,
E     +     'before_isolation_scope': '1',
E     ?                               + +
E       }

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@szokeasaurusrex szokeasaurusrex marked this pull request as ready for review June 12, 2025 12:06
@szokeasaurusrex szokeasaurusrex requested a review from a team as a code owner June 12, 2025 12:06
@szokeasaurusrex
Copy link
Member Author

Looks like tests are failing because the non-string values were being asserted in the test suites

@szokeasaurusrex szokeasaurusrex marked this pull request as draft June 13, 2025 12:47
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.

Ensure tag values are strings
2 participants