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, ), ]