Skip to content

Commit 95e55d3

Browse files
mjnoviceclaude
andauthored
feat: add internal tenant/account headers for local flow tracing (#1392)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 048dafc commit 95e55d3

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/uipath/tracing/_otel_exporters.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,19 @@ def __init__(
122122
super().__init__()
123123
self.base_url = self._get_base_url()
124124
self.auth_token = os.environ.get("UIPATH_ACCESS_TOKEN")
125-
self.headers = {
125+
self.headers: dict[str, str] = {
126126
"Content-Type": "application/json",
127127
"Authorization": f"Bearer {self.auth_token}",
128128
}
129129

130+
if os.environ.get("UIPATH_TRACE_BASE_URL"):
131+
self.headers["X-UiPath-Internal-TenantId"] = os.environ.get(
132+
"UIPATH_TENANT_ID", ""
133+
)
134+
self.headers["X-UiPath-Internal-AccountId"] = os.environ.get(
135+
"UIPATH_ORGANIZATION_ID", ""
136+
)
137+
130138
client_kwargs = get_httpx_client_kwargs()
131139

132140
self.http_client = httpx.Client(**client_kwargs, headers=self.headers)

tests/tracing/test_otel_exporters.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,50 @@ def test_get_base_url():
216216
assert exporter.base_url == "https://custom-trace.example.com/prefix"
217217

218218

219+
def test_internal_headers_set_when_trace_base_url_present():
220+
"""Test that internal tenant/account headers are set when UIPATH_TRACE_BASE_URL is configured."""
221+
with patch.dict(
222+
os.environ,
223+
{
224+
"UIPATH_TRACE_BASE_URL": "http://localhost:8888/llmops_",
225+
"UIPATH_ACCESS_TOKEN": "test-token",
226+
"UIPATH_TENANT_ID": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
227+
"UIPATH_ORGANIZATION_ID": "11111111-2222-3333-4444-555555555555",
228+
},
229+
clear=True,
230+
):
231+
with patch("uipath.tracing._otel_exporters.httpx.Client"):
232+
exporter = LlmOpsHttpExporter()
233+
234+
assert (
235+
exporter.headers["X-UiPath-Internal-TenantId"]
236+
== "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
237+
)
238+
assert (
239+
exporter.headers["X-UiPath-Internal-AccountId"]
240+
== "11111111-2222-3333-4444-555555555555"
241+
)
242+
243+
244+
def test_internal_headers_not_set_without_trace_base_url():
245+
"""Test that internal headers are NOT set when UIPATH_TRACE_BASE_URL is absent (cloud mode)."""
246+
with patch.dict(
247+
os.environ,
248+
{
249+
"UIPATH_URL": "https://cloud.uipath.com/org/tenant",
250+
"UIPATH_ACCESS_TOKEN": "test-token",
251+
"UIPATH_TENANT_ID": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
252+
"UIPATH_ORGANIZATION_ID": "11111111-2222-3333-4444-555555555555",
253+
},
254+
clear=True,
255+
):
256+
with patch("uipath.tracing._otel_exporters.httpx.Client"):
257+
exporter = LlmOpsHttpExporter()
258+
259+
assert "X-UiPath-Internal-TenantId" not in exporter.headers
260+
assert "X-UiPath-Internal-AccountId" not in exporter.headers
261+
262+
219263
def test_send_with_retries_success():
220264
"""Test _send_with_retries method with successful response."""
221265
with patch("uipath.tracing._otel_exporters.httpx.Client"):

0 commit comments

Comments
 (0)