From ee4753307e5ad184b3826ed98035d63d44d792b3 Mon Sep 17 00:00:00 2001 From: Aaron Diamond-Reivich Date: Thu, 29 Jan 2026 11:17:59 -0500 Subject: [PATCH] mito-ai: identify github action logs --- mito-ai/mito_ai/utils/create.py | 11 +++++------ mito-ai/mito_ai/utils/telemetry_utils.py | 13 +++++++------ mito-ai/mito_ai/utils/utils.py | 11 +++++++++++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/mito-ai/mito_ai/utils/create.py b/mito-ai/mito_ai/utils/create.py index 5dc312e67b..75ff7541b6 100644 --- a/mito-ai/mito_ai/utils/create.py +++ b/mito-ai/mito_ai/utils/create.py @@ -14,11 +14,11 @@ from typing import Literal, Optional from mito_ai.utils.db import (MITO_FOLDER, USER_JSON_PATH, set_user_field) -from mito_ai.utils.schema import (GITHUB_ACTION_EMAIL, GITHUB_ACTION_ID, - UJ_STATIC_USER_ID, UJ_USER_EMAIL, - USER_JSON_DEFAULT) +from mito_ai.utils.schema import (GITHUB_ACTION_EMAIL, + GITHUB_ACTION_ID, UJ_STATIC_USER_ID, + UJ_USER_EMAIL, USER_JSON_DEFAULT) from mito_ai.utils.telemetry_utils import identify -from mito_ai.utils.utils import is_running_test +from mito_ai.utils.utils import is_github_actions, is_running_test def is_user_json_exists_and_valid_json() -> bool: @@ -66,8 +66,7 @@ def try_create_user_json_file() -> None: if temp_user_id: set_user_field(UJ_STATIC_USER_ID, temp_user_id) - # Finally, we take special care to put all the testing/CI environments - # (e.g. Github actions) under one ID and email + # Finally, we take special care to put CI under a known ID and email. if is_running_test(): set_user_field(UJ_STATIC_USER_ID, GITHUB_ACTION_ID) set_user_field(UJ_USER_EMAIL, GITHUB_ACTION_EMAIL) diff --git a/mito-ai/mito_ai/utils/telemetry_utils.py b/mito-ai/mito_ai/utils/telemetry_utils.py index 4fa1d78cf7..a0a6ea9091 100644 --- a/mito-ai/mito_ai/utils/telemetry_utils.py +++ b/mito-ai/mito_ai/utils/telemetry_utils.py @@ -8,7 +8,7 @@ from mito_ai.utils.schema import UJ_AI_MITO_API_NUM_USAGES, UJ_MITOSHEET_TELEMETRY, UJ_STATIC_USER_ID, UJ_USER_EMAIL, UJ_FEEDBACKS_V2 from mito_ai.utils.db import get_user_field from mito_ai._version import __version__ -from mito_ai.utils.utils import is_running_test +from mito_ai.utils.utils import is_github_actions, is_running_test from mito_ai.completions.models import MessageType import analytics @@ -139,9 +139,10 @@ def identify(key_type: Optional[str] = None, is_electron: Optional[bool] = None) # becase we are only sending this info to the first completion_handler identify call. params['is_mito_desktop'] = is_electron - if not is_running_test(): + # Log identify for real users and for GitHub Actions CI (user id: mito-github-action) + if not is_running_test() or is_github_actions(): # TODO: If the user is in JupyterLite, we need to do some extra work. - # You can see this in the mitosheet package. + # You can see this in the mitosheet package. try: analytics.identify(static_user_id, params) except Exception as e: @@ -220,9 +221,9 @@ def log( if is_enterprise(): return - # Finally, do the acutal logging. We do not log anything when tests are - # running, or if telemetry is turned off - if not is_running_test() and telemetry_turned_on(key_type): + # Log events for real users and for GitHub Actions CI (user id: mito-github-action). + # Skip logging for local pytest and other non-GitHub-Actions CI. + if (not is_running_test() or is_github_actions()) and telemetry_turned_on(key_type): # TODO: If the user is in JupyterLite, we need to do some extra work. # You can see this in the mitosheet package. diff --git a/mito-ai/mito_ai/utils/utils.py b/mito-ai/mito_ai/utils/utils.py index f71cbf136d..1c26742b80 100644 --- a/mito-ai/mito_ai/utils/utils.py +++ b/mito-ai/mito_ai/utils/utils.py @@ -30,6 +30,17 @@ def is_running_test() -> bool: return running_pytests or running_ci + +def is_github_actions() -> bool: + """ + Returns True if the current code is running inside GitHub Actions CI. + GitHub sets GITHUB_ACTIONS=true in the environment for workflow runs. + Used to enable telemetry for CI runs (with a dedicated user id) while + still skipping telemetry for local pytest runs. + """ + return os.environ.get('GITHUB_ACTIONS') == 'true' + + def get_installed_packages() -> List[str]: """ Get a list of all installed packages.