Merge pull request 'perf: replace json.dumps serialization test with isinstance fast path (#96)' (#109) from ai/major-domo-v2-96 into next-release
All checks were successful
Build Docker Image / build (push) Successful in 1m13s

Reviewed-on: #109
This commit is contained in:
cal 2026-03-20 17:38:57 +00:00
commit 0c041bce99

View File

@ -24,6 +24,8 @@ JSONValue = Union[
str, int, float, bool, None, dict[str, Any], list[Any] # nested object # arrays
]
_SERIALIZABLE_TYPES = (str, int, float, bool, type(None))
class JSONFormatter(logging.Formatter):
"""Custom JSON formatter for structured file logging."""
@ -93,11 +95,11 @@ class JSONFormatter(logging.Formatter):
extra_data = {}
for key, value in record.__dict__.items():
if key not in excluded_keys:
# Ensure JSON serializable
try:
json.dumps(value)
if isinstance(value, _SERIALIZABLE_TYPES) or isinstance(
value, (list, dict)
):
extra_data[key] = value
except (TypeError, ValueError):
else:
extra_data[key] = str(value)
if extra_data: