From 552b973a256c0f4a9f96e36feb70f4fc15fb371b Mon Sep 17 00:00:00 2001 From: ElenaKhaustova <157851531+ElenaKhaustova@users.noreply.github.com> Date: Tue, 10 Sep 2024 17:49:25 +0100 Subject: [PATCH] fix(telemetry): Set default identity value (#830) * Set default identity Signed-off-by: Elena Khaustova * Updated test_before_command_run_anonymous Signed-off-by: Elena Khaustova * Fix lint Signed-off-by: Elena Khaustova --------- Signed-off-by: Elena Khaustova --- kedro-telemetry/kedro_telemetry/plugin.py | 6 +++--- kedro-telemetry/tests/test_plugin.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/kedro-telemetry/kedro_telemetry/plugin.py b/kedro-telemetry/kedro_telemetry/plugin.py index dd8b46877..136201c3d 100644 --- a/kedro-telemetry/kedro_telemetry/plugin.py +++ b/kedro-telemetry/kedro_telemetry/plugin.py @@ -49,6 +49,7 @@ CONFIG_FILENAME = "telemetry.toml" PYPROJECT_CONFIG_NAME = "pyproject.toml" UNDEFINED_PACKAGE_NAME = "undefined_package_name" +MISSING_USER_IDENTITY = "missing_user_identity" logger = logging.getLogger(__name__) @@ -240,7 +241,7 @@ def _send_telemetry_heap_event(self, event_name: str): try: _send_heap_event( event_name=event_name, - identity=self._user_uuid, + identity=self._user_uuid if self._user_uuid else MISSING_USER_IDENTITY, properties=self._event_properties, ) self._sent = True @@ -323,9 +324,8 @@ def _send_heap_event( "event": event_name, "timestamp": datetime.now().strftime(TIMESTAMP_FORMAT), "properties": properties or {}, + "identity": identity, } - if identity: - data["identity"] = identity try: resp = requests.post( diff --git a/kedro-telemetry/tests/test_plugin.py b/kedro-telemetry/tests/test_plugin.py index c100dd9e1..048f17561 100644 --- a/kedro-telemetry/tests/test_plugin.py +++ b/kedro-telemetry/tests/test_plugin.py @@ -16,6 +16,7 @@ from kedro_telemetry.plugin import ( _SKIP_TELEMETRY_ENV_VAR_KEYS, KNOWN_CI_ENV_VAR_KEYS, + MISSING_USER_IDENTITY, KedroTelemetryHook, _check_for_telemetry_consent, _is_known_ci_env, @@ -347,7 +348,7 @@ def test_before_command_run_anonymous(self, mocker, fake_metadata): expected_calls = [ mocker.call( event_name="CLI command", - identity="", + identity=MISSING_USER_IDENTITY, properties=generic_properties, ), ]