Skip to content

Commit 5d2c89d

Browse files
committed
fix(trace): fix traced serialization
1 parent 4e6c725 commit 5d2c89d

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath"
3-
version = "2.1.57"
3+
version = "2.1.58"
44
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"

src/uipath/tracing/_utils.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,36 @@
88
from datetime import datetime
99
from os import environ as env
1010
from typing import Any, Dict, Optional
11+
from zoneinfo import ZoneInfo
1112

1213
from opentelemetry.sdk.trace import ReadableSpan
1314
from opentelemetry.trace import StatusCode
1415

1516
logger = logging.getLogger(__name__)
1617

1718

19+
def _simple_serialize_defaults(obj):
20+
if hasattr(obj, "model_dump"):
21+
return obj.model_dump(exclude_none=True, mode="json")
22+
if hasattr(obj, "dict"):
23+
return obj.dict()
24+
if hasattr(obj, "to_dict"):
25+
return obj.to_dict()
26+
27+
if isinstance(obj, (set, tuple)):
28+
if hasattr(obj, "_asdict") and callable(obj._asdict):
29+
return obj._asdict()
30+
return list(obj)
31+
32+
if isinstance(obj, datetime.datetime):
33+
return obj.isoformat()
34+
35+
if isinstance(obj, (datetime.timezone, ZoneInfo)):
36+
return obj.tzname(None)
37+
38+
return str(obj)
39+
40+
1841
@dataclass
1942
class UiPathSpan:
2043
"""Represents a span in the UiPath tracing system."""
@@ -233,7 +256,7 @@ def format_args_for_trace_json(
233256
) -> str:
234257
"""Return a JSON string of inputs from the function signature."""
235258
result = _SpanUtils.format_args_for_trace(signature, *args, **kwargs)
236-
return json.dumps(result, default=str)
259+
return json.dumps(result, default=_simple_serialize_defaults)
237260

238261
@staticmethod
239262
def format_args_for_trace(

0 commit comments

Comments
 (0)