Skip to content

Commit 8df2799

Browse files
cfauchereClement Fauchereclaude
authored
fix(platform): use agent trace ID from UIPATH_TRACE_ID in trace header (#1551)
Co-authored-by: Clement Fauchere <clement.fauchere@uipath.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ec4b750 commit 8df2799

4 files changed

Lines changed: 22 additions & 10 deletions

File tree

packages/uipath-platform/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-platform"
3-
version = "0.1.22"
3+
version = "0.1.23"
44
description = "HTTP client library for programmatic access to UiPath Platform"
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.11"

packages/uipath-platform/src/uipath/platform/common/_base_service.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,32 @@ def _get_caller_component() -> str:
6767

6868

6969
def _inject_trace_context(headers: dict[str, str]) -> None:
70-
"""Inject UiPath trace context header from the active OTEL span.
70+
"""Inject UiPath trace context header.
7171
72-
Prefers the LLMOps tool span (from ContextVar) over the raw OTEL span,
73-
so the header carries the span ID visible in the LLMOps trace.
72+
Trace ID: uses the agent trace ID from UIPATH_TRACE_ID env var (same
73+
remapping the LLMOps exporter applies), falling back to the OTEL trace ID.
74+
Span ID: uses the LLMOps tool span (via external span provider) so the
75+
span ID matches what's visible in the LLMOps trace UI.
7476
"""
7577
from uipath.core.tracing.span_utils import UiPathSpanUtils
7678

79+
from ._config import UiPathConfig
80+
from ._span_utils import _SpanUtils
81+
7782
llmops_span = UiPathSpanUtils.get_external_current_span()
7883
span = llmops_span or trace.get_current_span()
7984
ctx = span.get_span_context()
80-
if ctx.trace_id and ctx.span_id:
81-
headers[_TRACE_PARENT_HEADER] = (
82-
f"00-{format_trace_id(ctx.trace_id)}-{format_span_id(ctx.span_id)}-01"
83-
)
85+
if not (ctx.trace_id and ctx.span_id):
86+
return
87+
88+
config_trace_id = UiPathConfig.trace_id
89+
trace_id = (
90+
_SpanUtils.normalize_trace_id(config_trace_id)
91+
if config_trace_id
92+
else format_trace_id(ctx.trace_id)
93+
)
94+
span_id = format_span_id(ctx.span_id)
95+
headers[_TRACE_PARENT_HEADER] = f"00-{trace_id}-{span_id}-01"
8496

8597

8698
class BaseService:

packages/uipath-platform/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/uipath/uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)