feat(platform): include jobKey in LLM Gateway trace baggage#1731
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
jobKeyfromUiPathConfig.job_keyto the emittedx-uipath-tracebaggageentries 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}") |
089244b to
a01bb31
Compare
🚨 Heads up:
|
a01bb31 to
f3b7585
Compare
ctiliescuuipath
approved these changes
Jul 2, 2026
f3b7585 to
a524a07
Compare
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>
bd563ab to
a2769f9
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
build_trace_context_headers(uipath/platform/chat/llm_trace_context.py) propagatesfolderKey,agentId, andprocessKeyintox-uipath-tracebaggage, but notjobKey— even thoughUiPathConfig.job_keyis available. LLM Gateway now builds the model-call span from this baggage (see the LLMGateway span work), so a missingjobKeymeans the span can't be attributed to the originating job.Today callers compensate by hand-injecting
jobKeythroughextra_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 existingprocessKeyblock:Gated by the existing
EnableTraceContextHeadersflag like the rest of the function; no behavior change when the flag is off.Note
Callers that already inject
jobKeyviaextra_baggagewill 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