Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/uipath-platform/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "uipath-platform"
version = "0.3.0"
version = "0.3.1"
description = "HTTP client library for programmatic access to UiPath Platform"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""W3C-style trace context headers for LLM Gateway requests."""

from opentelemetry import trace
from uipath.core.feature_flags import FeatureFlags
from uipath.core.tracing.span_utils import UiPathSpanUtils

from ..common._config import UiPathConfig
Expand All @@ -21,12 +20,9 @@ def build_trace_context_headers(
extra_baggage: Additional baggage entries (e.g. ``["source=agents"]``)
that callers can inject alongside the platform-level entries.

Returns an empty dict when the ``EnableTraceContextHeaders`` feature flag
is not enabled, or when no active span is present.
Returns an empty dict when there is no active span and no platform-level
baggage to send.
"""
if not FeatureFlags.is_flag_enabled("EnableTraceContextHeaders"):
return {}

headers: dict[str, str] = {}
llmops_span = UiPathSpanUtils.get_external_current_span()
span = llmops_span or trace.get_current_span()
Expand Down
33 changes: 3 additions & 30 deletions packages/uipath-platform/tests/services/test_llm_trace_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@

from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.trace import NonRecordingSpan, SpanContext, TraceFlags
from uipath.core.feature_flags import FeatureFlags

from uipath.platform.chat.llm_trace_context import build_trace_context_headers
from uipath.platform.constants import ENV_PROJECT_KEY

FEATURE_FLAG = "EnableTraceContextHeaders"


def _make_span():
"""Create a real OTEL span for testing."""
Expand All @@ -20,26 +17,8 @@ def _make_span():
return tracer.start_span("test-span")


class TestFeatureFlagDisabled:
"""When the feature flag is off, no headers are returned."""

def setup_method(self) -> None:
FeatureFlags.reset_flags()

def test_returns_empty_dict_by_default(self) -> None:
assert build_trace_context_headers() == {}

def test_returns_empty_dict_when_explicitly_disabled(self) -> None:
FeatureFlags.configure_flags({FEATURE_FLAG: False})
assert build_trace_context_headers() == {}


class TestTraceparentHeader:
"""When enabled, x-uipath-traceparent-id is populated from config + span."""

def setup_method(self) -> None:
FeatureFlags.reset_flags()
FeatureFlags.configure_flags({FEATURE_FLAG: True})
"""x-uipath-traceparent-id is populated from config + span."""

def test_traceparent_from_config_and_span(self) -> None:
span = _make_span()
Expand Down Expand Up @@ -111,14 +90,12 @@ def test_no_traceparent_with_invalid_span(self) -> None:


class TestBaggageHeader:
"""When enabled, x-uipath-tracebaggage is populated from UiPathConfig."""
"""x-uipath-tracebaggage is populated from UiPathConfig."""

def setup_method(self) -> None:
from uipath.platform.common._span_utils import _read_config_id

_read_config_id.cache_clear()
FeatureFlags.reset_flags()
FeatureFlags.configure_flags({FEATURE_FLAG: True})

def test_all_env_vars_present(self) -> None:
env = {
Expand Down Expand Up @@ -199,11 +176,7 @@ def test_extra_baggage_only(self) -> None:


class TestBothHeaders:
"""When enabled with an active span and env vars, both headers are present."""

def setup_method(self) -> None:
FeatureFlags.reset_flags()
FeatureFlags.configure_flags({FEATURE_FLAG: True})
"""With an active span and env vars, both headers are present."""

def test_both_headers_present(self) -> None:
span = _make_span()
Expand Down
2 changes: 1 addition & 1 deletion packages/uipath-platform/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/uipath/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading