Skip to content

Commit 315dbe9

Browse files
committed
fix: adjust serialization
1 parent a5b48f8 commit 315dbe9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

posthog/exception_utils.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -948,9 +948,13 @@ def _serialize_variable_value(value, limiter, max_length=1024):
948948
elif isinstance(value, bool):
949949
result = str(value)
950950
elif isinstance(value, (int, float)):
951-
result = str(value)
951+
result_size = len(str(value))
952+
if not limiter.can_add(result_size):
953+
return None
954+
limiter.add(result_size)
955+
return value
952956
elif isinstance(value, str):
953-
result = repr(value)
957+
result = value
954958
else:
955959
result = json.dumps(value)
956960

posthog/test/test_exception_capture.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,22 @@ def process_data():
9292
assert b"code_variables" in output
9393

9494
# Variables from trigger_error frame
95-
assert b"'my_string': \"'hello world'\"" in output
96-
assert b"'my_number': '42'" in output
95+
assert b"'my_string': 'hello world'" in output
96+
assert b"'my_number': 42" in output
9797
assert b"'my_bool': 'True'" in output
9898
assert b'"my_dict": "{\\"name\\": \\"test\\", \\"value\\": 123}"' in output
9999
assert b'"my_obj": "<UnserializableObject>"' in output
100100
assert b"'my_password': '$$_posthog_redacted_based_on_masking_rules_$$'" in output
101101
assert b"'__should_be_ignored':" not in output
102102

103103
# Variables from intermediate_function frame
104-
assert b"'request_id': \"'abc-123'\"" in output
105-
assert b"'user_count': '100'" in output
104+
assert b"'request_id': 'abc-123'" in output
105+
assert b"'user_count': 100" in output
106106
assert b"'is_active': 'True'" in output
107107

108108
# Variables from process_data frame
109-
assert b"'batch_size': '50'" in output
110-
assert b"'retry_count': '3'" in output
109+
assert b"'batch_size': 50" in output
110+
assert b"'retry_count': 3" in output
111111

112112

113113
def test_code_variables_context_override(tmpdir):
@@ -152,7 +152,7 @@ def process_data():
152152
assert b"ZeroDivisionError" in output
153153
assert b"code_variables" in output
154154
assert b"'bank': '$$_posthog_redacted_based_on_masking_rules_$$'" in output
155-
assert b"'__dunder_var': \"'should_be_visible'\"" in output
155+
assert b"'__dunder_var': 'should_be_visible'" in output
156156

157157

158158
def test_code_variables_size_limiter(tmpdir):

0 commit comments

Comments
 (0)