Skip to content
Merged
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 packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-platform"
version = "0.2.5"
version = "0.2.6"
description = "HTTP client library for programmatic access to UiPath Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ class UiPathSpan:
attributes: str | Dict[str, Any] # Support both str (legacy) and dict (optimized)
parent_id: Optional[str] = None # 16-char hex (OTEL span ID format)
start_time: str = field(default_factory=lambda: datetime.now().isoformat())
end_time: str = field(default_factory=lambda: datetime.now().isoformat())
# None means the span has not ended yet. Serialized as null — the LLMOps v3
# ingest contract (SpanV3Req.EndTime) is nullable, and downstream consumers
# (traceview UI, Insights OTLP export) rely on "EndTime set" meaning "span
# ended": fabricating a value here makes in-progress snapshots look terminal.
end_time: Optional[str] = None
status: SpanStatus = SpanStatus.OK
created_at: str = field(default_factory=lambda: datetime.now().isoformat() + "Z")
updated_at: str = field(default_factory=lambda: datetime.now().isoformat() + "Z")
Expand Down Expand Up @@ -542,13 +546,14 @@ def otel_span_to_uipath_span(
(otel_span.start_time or 0) / 1e9
).isoformat()

# A live (not-yet-ended) OTel span has end_time None — preserve that rather
# than stamping now(): a fabricated EndTime makes in-progress upserts
# (upsert_span RUNNING → OK lifecycle) indistinguishable from ended spans.
end_time_str = None
if otel_span.end_time is not None:
end_time_str = datetime.fromtimestamp(
(otel_span.end_time or 0) / 1e9
).isoformat()
else:
end_time_str = datetime.now().isoformat()

return UiPathSpan(
id=span_id,
Expand Down
31 changes: 31 additions & 0 deletions packages/uipath-platform/tests/services/test_span_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,34 @@ def test_on_start_stamps_full_hierarchy(self) -> None:
assert "version" not in hierarchy[1]
finally:
ReferenceContextAccessor.reset(token)


class TestLiveSpanEndTime:
"""A live (not-yet-ended) OTEL span must convert with end_time=None.

Fabricating EndTime=now() for in-progress upserts (the RUNNING -> OK
lifecycle used by upsert_span) makes open snapshots indistinguishable
from ended spans downstream: the traceview UI shows phantom sub-ms
durations and the Insights OTLP export's unclosed-span filter never
fires, so every span exports twice.
"""

@patch.dict(os.environ, {"UIPATH_ORGANIZATION_ID": "test-org"})
def test_live_span_converts_with_none_end_time(self) -> None:
mock_span = _make_otel_span({})
mock_span.end_time = None

uipath_span = _SpanUtils.otel_span_to_uipath_span(mock_span)
span_dict = uipath_span.to_dict()

assert uipath_span.end_time is None
assert span_dict["EndTime"] is None

@patch.dict(os.environ, {"UIPATH_ORGANIZATION_ID": "test-org"})
def test_ended_span_keeps_real_end_time(self) -> None:
mock_span = _make_otel_span({})

uipath_span = _SpanUtils.otel_span_to_uipath_span(mock_span)

assert uipath_span.end_time is not None
assert uipath_span.to_dict()["EndTime"] == uipath_span.end_time
2 changes: 1 addition & 1 deletion packages/uipath-platform/uv.lock

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

2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

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

Loading