Skip to content

Commit

Permalink
Try to_dict method when encoding JSON (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmojaki authored Jan 15, 2025
1 parent 6ab0661 commit c2806ef
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions logfire/_internal/json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ def to_json_value(o: Any, seen: set[int]) -> JsonValue:

if isinstance(o, Sequence):
return [to_json_value(item, seen) for item in o] # type: ignore

try:
# Some VertexAI classes have this method. They have no common base class.
# Seems like a sensible thing to try in general.
return to_json_value(o.to_dict(), seen)
except Exception: # currently redundant, but future-proof
pass
except Exception: # pragma: no cover
pass

Expand Down

0 comments on commit c2806ef

Please sign in to comment.