Skip to content

Commit 4afbc8c

Browse files
cfauchereClement Fauchereclaude
authored
feat(platform): inject x-uipath-traceparent-id on all outbound HTTP requests (#1535)
Co-authored-by: Clement Fauchere <clement.fauchere@uipath.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Special thanks to Caleb Martin
1 parent 96e1894 commit 4afbc8c

4 files changed

Lines changed: 20 additions & 3 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.17"
3+
version = "0.1.18"
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
HTTPStatusError,
1212
Response,
1313
)
14+
from opentelemetry import trace
15+
from opentelemetry.trace import format_span_id, format_trace_id
1416
from tenacity import (
1517
retry,
1618
retry_if_exception,
@@ -61,6 +63,19 @@ def _get_caller_component() -> str:
6163
return ""
6264

6365

66+
_TRACE_PARENT_HEADER = "x-uipath-traceparent-id"
67+
68+
69+
def _inject_trace_context(headers: dict[str, str]) -> None:
70+
"""Inject UiPath trace context header from the active OTEL span."""
71+
span = trace.get_current_span()
72+
ctx = span.get_span_context()
73+
if ctx.trace_id and ctx.span_id:
74+
headers[_TRACE_PARENT_HEADER] = (
75+
f"00-{format_trace_id(ctx.trace_id)}-{format_span_id(ctx.span_id)}-01"
76+
)
77+
78+
6479
class BaseService:
6580
def __init__(
6681
self, config: UiPathApiConfig, execution_context: UiPathExecutionContext
@@ -106,6 +121,7 @@ def request(
106121

107122
kwargs.setdefault("headers", {})
108123
kwargs["headers"][HEADER_USER_AGENT] = user_agent_value(specific_component)
124+
_inject_trace_context(kwargs["headers"])
109125

110126
override = resolve_service_url(str(url))
111127
if override:
@@ -150,6 +166,7 @@ async def request_async(
150166
kwargs["headers"][HEADER_USER_AGENT] = user_agent_value(
151167
self._specific_component
152168
)
169+
_inject_trace_context(kwargs["headers"])
153170

154171
override = resolve_service_url(str(url))
155172
if override:

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)