Skip to content

feat(platform): add W3C trace context headers to LLM Gateway requests#1612

Merged
ctiliescuuipath merged 2 commits into
mainfrom
feat/trace-context-headers-llm-gateway
May 5, 2026
Merged

feat(platform): add W3C trace context headers to LLM Gateway requests#1612
ctiliescuuipath merged 2 commits into
mainfrom
feat/trace-context-headers-llm-gateway

Conversation

@ctiliescuuipath
Copy link
Copy Markdown
Contributor

Summary

  • Add x-uipath-traceparent-id and x-uipath-tracebaggage headers to all LLM Gateway HTTP calls
  • Headers follow the W3C Trace Context spec, per TraceView client SDK docs
  • Gated behind the EnableTraceContextHeaders feature flag (env var: UIPATH_FEATURE_EnableTraceContextHeaders=true)
  • Baggage includes: source=agents, folderKey, agentId, processKey
  • build_trace_context_headers() defined once in llm_trace_context.py, consumed by both UiPathLlmChatService/UiPathOpenAIService and uipath-langchain legacy clients
  • Bump uipath-platform version to 0.1.41

Test plan

  • Unit tests added in test_llm_trace_context.py (9 tests covering flag on/off, traceparent format, baggage content)
  • Existing LLM service tests pass (no regressions)
  • Manual test with playground agent using UIPATH_FEATURE_EnableTraceContextHeaders=true

🤖 Generated with Claude Code

@ctiliescuuipath ctiliescuuipath force-pushed the feat/trace-context-headers-llm-gateway branch from 594f8f1 to 24cc085 Compare May 4, 2026 10:38
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels May 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

🚨 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 →

@ctiliescuuipath ctiliescuuipath force-pushed the feat/trace-context-headers-llm-gateway branch from 08e43ed to dd55382 Compare May 4, 2026 10:49
span_id = format(ctx.span_id, "016x")
headers["x-uipath-traceparent-id"] = f"00-{trace_id}-{span_id}"

baggage_parts: list[str] = ["source=agents"]
Copy link
Copy Markdown
Collaborator

@radu-mocanu radu-mocanu May 5, 2026

Choose a reason for hiding this comment

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

this part should be moved to uipath-langchain and the other integration repos.
uipath-platform should remain framework/runtime agnostic (since function projects will also use it)

Suggested change
baggage_parts: list[str] = ["source=agents"]
baggage_parts: list[str]

baggage_parts: list[str] = ["source=agents"]
if folder_key := os.getenv(ENV_FOLDER_KEY):
baggage_parts.append(f"folderKey={folder_key}")
if agent_id := os.getenv(ENV_UIPATH_PROCESS_UUID):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if agent_id := os.getenv(ENV_UIPATH_PROCESS_UUID):
if agent_id := UiPathConfig.process_uuid:

let s use UiPathConfig here instead of using direct env vars accessors. we can even cache the data at that layer.

please note that some properties may not be available at the moment in UiPathConfig, we should add those

Add x-uipath-traceparent-id and x-uipath-tracebaggage headers to all
LLM Gateway HTTP calls, gated behind the EnableTraceContextHeaders
feature flag. Headers follow the W3C Trace Context spec and include
source, folderKey, agentId, and processKey in the baggage.

Bump uipath-platform to 0.1.41.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ctiliescuuipath ctiliescuuipath force-pushed the feat/trace-context-headers-llm-gateway branch from dd55382 to 4c3b5af Compare May 5, 2026 10:51
…baggage API

Replace direct os.getenv() calls with UiPathConfig properties and remove
hardcoded source=agents baggage to keep uipath-platform framework-agnostic.
Add extra_baggage parameter so integration repos can inject their own entries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ctiliescuuipath ctiliescuuipath force-pushed the feat/trace-context-headers-llm-gateway branch from 4c3b5af to 090a043 Compare May 5, 2026 10:55
@ctiliescuuipath ctiliescuuipath merged commit 67466db into main May 5, 2026
155 checks passed
@ctiliescuuipath ctiliescuuipath deleted the feat/trace-context-headers-llm-gateway branch May 5, 2026 11:46
return {}

headers: dict[str, str] = {}
span = trace.get_current_span()
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.

you should use:

    from uipath.core.tracing.span_utils import UiPathSpanUtils

    llmops_span = UiPathSpanUtils.get_external_current_span()
    span = llmops_span or trace.get_current_span()

similar to https://github.com/UiPath/uipath-python/pull/1547/changes

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