Skip to content

Commit

Permalink
fix(telemetry): Set default identity value (#830)
Browse files Browse the repository at this point in the history
* Set default identity

Signed-off-by: Elena Khaustova <[email protected]>

* Updated test_before_command_run_anonymous

Signed-off-by: Elena Khaustova <[email protected]>

* Fix lint

Signed-off-by: Elena Khaustova <[email protected]>

---------

Signed-off-by: Elena Khaustova <[email protected]>
  • Loading branch information
ElenaKhaustova authored Sep 10, 2024
1 parent 3da39f7 commit 552b973
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions kedro-telemetry/kedro_telemetry/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion kedro-telemetry/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
),
]
Expand Down

0 comments on commit 552b973

Please sign in to comment.