diff --git a/packages/uipath/docs/core/environment_variables.md b/packages/uipath/docs/core/environment_variables.md index bcf1bcc8b..c6a4e72a2 100644 --- a/packages/uipath/docs/core/environment_variables.md +++ b/packages/uipath/docs/core/environment_variables.md @@ -58,6 +58,8 @@ Telemetry is enabled by default. You can opt out by setting the `UIPATH_TELEMETR UIPATH_TELEMETRY_ENABLED=false ``` +Setting `UIPATH_TELEMETRY_DISABLED=true` has the same effect and takes precedence over `UIPATH_TELEMETRY_ENABLED`. + ## Runtime When executing processes or starting jobs, you can configure environment variables through the UiPath Orchestrator interface. For sensitive information like API keys and secrets, we strongly recommend using secret assets instead of environment variables. Secret assets provide enhanced security and better management capabilities. diff --git a/packages/uipath/pyproject.toml b/packages/uipath/pyproject.toml index 9f3c76d5e..658811719 100644 --- a/packages/uipath/pyproject.toml +++ b/packages/uipath/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "uipath" -version = "2.15.4" +version = "2.15.5" description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools." readme = { file = "README.md", content-type = "text/markdown" } requires-python = ">=3.11" diff --git a/packages/uipath/src/uipath/telemetry/_constants.py b/packages/uipath/src/uipath/telemetry/_constants.py index fd9098def..581bc0bf0 100644 --- a/packages/uipath/src/uipath/telemetry/_constants.py +++ b/packages/uipath/src/uipath/telemetry/_constants.py @@ -4,6 +4,10 @@ PERIODIC_TELEMETRY_FLUSH_FEATURE_FLAG = "EnablePeriodicTelemetryFlush" +# Set to "true" by a host environment that turns telemetry off. +# Wins over UIPATH_TELEMETRY_ENABLED. +_ENV_TELEMETRY_DISABLED = "UIPATH_TELEMETRY_DISABLED" + _APP_INSIGHTS_EVENT_MARKER_ATTRIBUTE = "APPLICATION_INSIGHTS_EVENT_MARKER_ATTRIBUTE" _OTEL_RESOURCE_ATTRIBUTES = "OTEL_RESOURCE_ATTRIBUTES" _SDK_VERSION = "SdkVersion" diff --git a/packages/uipath/src/uipath/telemetry/_track.py b/packages/uipath/src/uipath/telemetry/_track.py index b2be4f90d..b86a53535 100644 --- a/packages/uipath/src/uipath/telemetry/_track.py +++ b/packages/uipath/src/uipath/telemetry/_track.py @@ -31,6 +31,7 @@ _CONNECTION_STRING_ALPHA, _CONNECTION_STRING_PROD, _CONNECTION_STRING_STAGING, + _ENV_TELEMETRY_DISABLED, _OTEL_RESOURCE_ATTRIBUTES, _PROJECT_KEY, _SDK_VERSION, @@ -512,7 +513,14 @@ class _TelemetryClient: @staticmethod def _is_enabled() -> bool: - """Check if telemetry is enabled at runtime.""" + """Check if telemetry is enabled at runtime. + + ``UIPATH_TELEMETRY_DISABLED=true`` turns it off whatever + ``UIPATH_TELEMETRY_ENABLED`` says, so a host environment can switch + telemetry off for the processes it starts. + """ + if os.getenv(_ENV_TELEMETRY_DISABLED, "").strip().lower() in ("true", "1"): + return False return os.getenv(ENV_TELEMETRY_ENABLED, "true").lower() == "true" @staticmethod diff --git a/packages/uipath/tests/telemetry/test_track.py b/packages/uipath/tests/telemetry/test_track.py index af7c8a616..a08b3615d 100644 --- a/packages/uipath/tests/telemetry/test_track.py +++ b/packages/uipath/tests/telemetry/test_track.py @@ -739,6 +739,33 @@ def test_is_enabled_case_insensitive(self): with patch.dict(os.environ, {"UIPATH_TELEMETRY_ENABLED": "False"}): assert _TelemetryClient._is_enabled() is False + def test_is_enabled_false_when_telemetry_disabled(self): + """UIPATH_TELEMETRY_DISABLED=true turns telemetry off.""" + with patch.dict(os.environ, {"UIPATH_TELEMETRY_DISABLED": "true"}, clear=True): + assert _TelemetryClient._is_enabled() is False + + def test_disabled_wins_over_enabled(self): + """UIPATH_TELEMETRY_DISABLED=true wins over UIPATH_TELEMETRY_ENABLED=true.""" + env = {"UIPATH_TELEMETRY_DISABLED": "True", "UIPATH_TELEMETRY_ENABLED": "true"} + with patch.dict(os.environ, env, clear=True): + assert _TelemetryClient._is_enabled() is False + + def test_disabled_not_true_keeps_telemetry_on(self): + """Any other UIPATH_TELEMETRY_DISABLED value leaves the default in place.""" + for value in ("false", "", "0"): + with patch.dict( + os.environ, {"UIPATH_TELEMETRY_DISABLED": value}, clear=True + ): + assert _TelemetryClient._is_enabled() is True + + def test_track_event_sends_nothing_when_telemetry_disabled(self): + """No event reaches the App Insights client when telemetry is disabled.""" + with patch.dict(os.environ, {"UIPATH_TELEMETRY_DISABLED": "true"}, clear=True): + with patch.object(_AppInsightsEventClient, "track_event") as mock_track: + _TelemetryClient.track_event("test_event", {"key": "value"}) + + mock_track.assert_not_called() + @patch.object(_TelemetryClient, "_is_enabled", return_value=False) def test_track_event_disabled(self, mock_is_enabled): """Test that track_event does nothing when telemetry is disabled.""" diff --git a/packages/uipath/uv.lock b/packages/uipath/uv.lock index ab608bcd9..42e39b292 100644 --- a/packages/uipath/uv.lock +++ b/packages/uipath/uv.lock @@ -2720,7 +2720,7 @@ wheels = [ [[package]] name = "uipath" -version = "2.15.4" +version = "2.15.5" source = { editable = "." } dependencies = [ { name = "applicationinsights" },