Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath"
version = "2.5.4"
version = "2.5.5"
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
7 changes: 7 additions & 0 deletions src/uipath/tracing/_otel_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,13 @@ def _process_span_attributes(self, span_data: Dict[str, Any]) -> None:
elif span_type == "toolCall":
self._map_tool_call_attributes(attributes)

# Parse JSON-encoded strings that should be objects (avoids double-encoding)
# OTEL only accepts primitives, so agents serialize dicts to JSON strings.
# Detect and parse any string that looks like JSON object/array.
for key, value in attributes.items():
if isinstance(value, str) and value and value[0] in "{[":
attributes[key] = _safe_parse_json(value)

# If attributes were a string (legacy path), serialize back
# If dict (optimized path), leave as dict - caller will serialize once at the end
if isinstance(attributes_val, str):
Expand Down
54 changes: 54 additions & 0 deletions tests/tracing/test_otel_exporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,60 @@ def test_unknown_span_type_preserved(self):
print("✓ UNKNOWN span preserved and processed correctly")
print(f"✓ Final attributes keys: {list(attributes.keys())}")

def test_json_strings_parsed_to_objects(self):
"""Test that JSON-encoded strings starting with { or [ are parsed to objects.

OTEL only accepts primitives, so agents serialize dicts/lists to JSON strings.
The exporter should parse these back to objects before final serialization.
"""
span_data = {
"Id": "test-span-id",
"TraceId": "test-trace-id",
"ParentId": None,
"Name": "Test span",
"StartTime": "2025-01-01T00:00:00Z",
"EndTime": "2025-01-01T00:00:01Z",
"Attributes": {
"type": "agentRun",
"inputSchema": '{"type": "object", "properties": {}}',
"outputSchema": '{"type": "object", "properties": {"content": {"type": "string"}}}',
"settings": '{"maxTokens": 16384, "temperature": 0.0}',
"toolCalls": '[{"id": "call_123", "name": "test_tool"}]',
"regularString": "not json",
"emptyString": "",
},
"Status": 1,
}

self.exporter._process_span_attributes(span_data)

attributes = span_data["Attributes"]
assert isinstance(attributes, dict)

# JSON strings should be parsed to objects
input_schema = attributes["inputSchema"]
assert isinstance(input_schema, dict)
self.assertEqual(input_schema["type"], "object")

output_schema = attributes["outputSchema"]
assert isinstance(output_schema, dict)
self.assertIn("content", output_schema["properties"])

settings = attributes["settings"]
assert isinstance(settings, dict)
self.assertEqual(settings["maxTokens"], 16384)

tool_calls = attributes["toolCalls"]
assert isinstance(tool_calls, list)
self.assertEqual(tool_calls[0]["name"], "test_tool")

# Non-JSON strings should remain as strings
self.assertIsInstance(attributes["regularString"], str)
self.assertEqual(attributes["regularString"], "not json")

self.assertIsInstance(attributes["emptyString"], str)
self.assertEqual(attributes["emptyString"], "")


class TestSpanFiltering:
"""Tests for filtering spans marked with telemetry.filter=drop."""
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.