-
Notifications
You must be signed in to change notification settings - Fork 552
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
base: master
Are you sure you want to change the base?
fix: Ensure tags values are strings #4459
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #4459 +/- ##
=======================================
Coverage 80.59% 80.60%
=======================================
Files 142 142
Lines 16030 16030
Branches 2745 2748 +3
=======================================
+ Hits 12920 12921 +1
Misses 2243 2243
+ Partials 867 866 -1
|
Looks like tests are failing because the non-string values were being asserted in the test suites |
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.
Some high-level thoughts:
- We seem to be stringifying the tags in multiple places. Do we need to do it in all of those? Is there a way to centralize it, e.g. move it to the end of the pipeline, e.g. in the serializer?
- Are we sure we're not changing anything user-facing, especially in callbacks? (E.g. if a user is accessing tags in a
before_send
or similar.)
def test_set_tag_handles_conversion_failure(): | ||
"""Test that set_tag handles objects that fail to convert to string.""" | ||
scope = Scope() | ||
|
||
# Create an object that raises an exception when str() is called | ||
class BadObject: | ||
def __str__(self): | ||
raise Exception("Cannot convert to string") | ||
|
||
def __repr__(self): | ||
return "BadObject()" | ||
|
||
bad_obj = BadObject() | ||
|
||
# This should not raise an exception | ||
scope.set_tag("bad_object", bad_obj) | ||
|
||
# The tag should be set with the repr value | ||
event = scope.apply_to_event({}, {}) | ||
tags = event.get("tags", {}) | ||
|
||
assert tags["bad_object"] == "BadObject()", "Tag should be set with repr value" | ||
|
||
|
||
def test_set_tags_handles_conversion_failure(): | ||
"""Test that set_tags handles objects that fail to convert to string.""" | ||
scope = Scope() | ||
|
||
# Create an object that raises an exception when str() is called | ||
class BadObject: | ||
def __str__(self): | ||
raise Exception("Cannot convert to string") | ||
|
||
def __repr__(self): | ||
return "BadObject()" | ||
|
||
bad_obj = BadObject() | ||
|
||
scope.set_tags( | ||
{ | ||
"good_tag1": "value1", | ||
"bad_tag": bad_obj, | ||
"good_tag2": 123, | ||
} | ||
) | ||
|
||
event = scope.apply_to_event({}, {}) | ||
tags = event.get("tags", {}) | ||
|
||
assert tags["good_tag1"] == "value1" | ||
assert tags["bad_tag"] == "BadObject()", "Tag should be set with repr value" | ||
assert tags["good_tag2"] == "123" |
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.
Maybe consolidate these two test cases into one?
Ensure tag values are strings before serializing an event or a transaction to an
Event
dictionary.Fixes #4391