feat(platform): add W3C trace context headers to LLM Gateway requests#1612
Conversation
594f8f1 to
24cc085
Compare
🚨 Heads up:
|
08e43ed to
dd55382
Compare
| span_id = format(ctx.span_id, "016x") | ||
| headers["x-uipath-traceparent-id"] = f"00-{trace_id}-{span_id}" | ||
|
|
||
| baggage_parts: list[str] = ["source=agents"] |
There was a problem hiding this comment.
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)
| 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): |
There was a problem hiding this comment.
| 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>
dd55382 to
4c3b5af
Compare
…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>
4c3b5af to
090a043
Compare
| return {} | ||
|
|
||
| headers: dict[str, str] = {} | ||
| span = trace.get_current_span() |
There was a problem hiding this comment.
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
Summary
x-uipath-traceparent-idandx-uipath-tracebaggageheaders to all LLM Gateway HTTP callsEnableTraceContextHeadersfeature flag (env var:UIPATH_FEATURE_EnableTraceContextHeaders=true)source=agents,folderKey,agentId,processKeybuild_trace_context_headers()defined once inllm_trace_context.py, consumed by bothUiPathLlmChatService/UiPathOpenAIServiceanduipath-langchainlegacy clientsuipath-platformversion to0.1.41Test plan
test_llm_trace_context.py(9 tests covering flag on/off, traceparent format, baggage content)UIPATH_FEATURE_EnableTraceContextHeaders=true🤖 Generated with Claude Code