Skip to content

feat(platform): include jobKey in LLM Gateway trace baggage#1731

Merged
RunnanJia merged 3 commits into
mainfrom
feat/trace-context-jobkey-baggage
Jul 10, 2026
Merged

feat(platform): include jobKey in LLM Gateway trace baggage#1731
RunnanJia merged 3 commits into
mainfrom
feat/trace-context-jobkey-baggage

Conversation

@RunnanJia

Copy link
Copy Markdown
Contributor

Why

build_trace_context_headers (uipath/platform/chat/llm_trace_context.py) propagates folderKey, agentId, and processKey into x-uipath-tracebaggage, but not jobKey — even though UiPathConfig.job_key is available. LLM Gateway now builds the model-call span from this baggage (see the LLMGateway span work), so a missing jobKey means the span can't be attributed to the originating job.

Today callers compensate by hand-injecting jobKey through extra_baggage (e.g. uipath-agents-python). Emitting it natively here fixes it once for every caller and lets those workarounds be removed.

What

One addition in build_trace_context_headers, mirroring the existing processKey block:

if job_key := UiPathConfig.job_key:
    baggage_parts.append(f"jobKey={job_key}")

Gated by the existing EnableTraceContextHeaders flag like the rest of the function; no behavior change when the flag is off.

Note

Callers that already inject jobKey via extra_baggage will momentarily send it twice in the comma-joined header; the LLM Gateway baggage parser is last-write-wins, so this is harmless. Those callers can drop the manual injection once this ships.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 17, 2026 17:00
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Jun 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the platform LLM trace context propagation to include jobKey in the x-uipath-tracebaggage header, enabling LLM Gateway spans to be attributed to the originating job without requiring callers to manually inject this baggage entry.

Changes:

  • Add jobKey from UiPathConfig.job_key to the emitted x-uipath-tracebaggage entries when trace context headers are enabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to +48
if job_key := UiPathConfig.job_key:
baggage_parts.append(f"jobKey={job_key}")
@RunnanJia RunnanJia force-pushed the feat/trace-context-jobkey-baggage branch from 089244b to a01bb31 Compare July 1, 2026 18:04
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

🚨 Heads up: uipath-langchain cross-tests are FAILING 🚨

Your changes may break the uipath-langchain-python integration.

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

@RunnanJia RunnanJia force-pushed the feat/trace-context-jobkey-baggage branch from a01bb31 to f3b7585 Compare July 1, 2026 18:14
@RunnanJia RunnanJia force-pushed the feat/trace-context-jobkey-baggage branch from f3b7585 to a524a07 Compare July 8, 2026 05:49
RunnanJia and others added 3 commits July 10, 2026 10:51
build_trace_context_headers emits folderKey/agentId/processKey but omits
jobKey, even though UiPathConfig.job_key is available. LLM Gateway now
builds the model-call span from this baggage, so without jobKey the span
cannot be attributed to the originating job. Callers currently work around
this by hand-injecting jobKey via extra_baggage; emitting it natively fixes
it once for every caller.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
build_trace_context_headers emitted x-uipath-traceparent-id as
"00-{trace}-{span}" with a 32-hex span id and no trace-flags segment. The
LLM Gateway parses this header strictly (UiPath.Tracing.TraceParent.TryParse):
it requires exactly four segments {version}-{32-hex trace}-{16-hex span}-{flags}
and a 16-hex span id. The malformed header was rejected, so the gateway
synthesized a fresh root trace for every LLM call and dropped the inbound
baggage — the gateway's completion (audit) span ended up under a different
traceId with a null parent, orphaned from the agent run, and the jobKey/source
baggage this PR adds never reached the gateway.

Fix: format the span id as 16 hex (`016x`, a span id is 64-bit) and append the
`-01` trace-flags segment. Verified safe for the other consumer (the Agents
backend parser is lenient: >=3 parts, no span-length check). Updated the test
to assert the correct 4-segment / 16-hex shape.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Rebased onto main (which had advanced to 0.2.6) and bumped to 0.2.7 so this
change publishes as a clean new release carrying the traceparent-format fix
and jobKey baggage.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@RunnanJia RunnanJia force-pushed the feat/trace-context-jobkey-baggage branch from bd563ab to a2769f9 Compare July 10, 2026 17:52
@sonarqubecloud

Copy link
Copy Markdown

@RunnanJia RunnanJia merged commit 8124543 into main Jul 10, 2026
165 checks passed
@RunnanJia RunnanJia deleted the feat/trace-context-jobkey-baggage branch July 10, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants