AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(agent/telemetry): Distinguish between `production` and `dev` environment based on VCS state
Reinier van der Leerfd5730b04aed
diff --git a/autogpts/autogpt/autogpt/app/telemetry.py b/autogpts/autogpt/autogpt/app/telemetry.pyindex d89e4e6c7d..9706781d7a 100644--- a/autogpts/autogpt/autogpt/app/telemetry.py+++ b/autogpts/autogpt/autogpt/app/telemetry.py@@ -3,7 +3,12 @@ import osimport clickfrom colorama import Fore, Style-from .utils import env_file_exists, get_git_user_email, set_env_config_value+from .utils import (+ env_file_exists,+ get_git_user_email,+ set_env_config_value,+ vcs_state_diverges_from_master,+)def setup_telemetry() -> None:@@ -49,7 +54,10 @@ def _setup_sentry() -> None:sentry_sdk.init(dsn="https://dc266f2f7a2381194d1c0fa36dff67d8@o4505260022104064.ingest.sentry.io/4506739844710400", # noqaenable_tracing=True,- environment=os.getenv("TELEMETRY_ENVIRONMENT"),+ environment=os.getenv(+ "TELEMETRY_ENVIRONMENT",+ "production" if not vcs_state_diverges_from_master() else "dev",+ ),)# Allow Sentry to distinguish between usersdiff --git a/autogpts/autogpt/autogpt/app/utils.py b/autogpts/autogpt/autogpt/app/utils.pyindex 5a2757161c..7b815e2c73 100644--- a/autogpts/autogpt/autogpt/app/utils.py+++ b/autogpts/autogpt/autogpt/app/utils.py@@ -1,3 +1,4 @@+import contextlibimport loggingimport osimport re@@ -84,6 +85,50 @@ def get_current_git_branch() -> str:return ""+def vcs_state_diverges_from_master() -> bool:+ """+ Returns whether a git repo is present and contains changes that are not in `master`.+ """+ paths_we_care_about = "autogpts/autogpt/autogpt/**/*.py"+ try:+ repo = Repo(search_parent_directories=True)++ # Check for uncommitted changes in the specified path+ uncommitted_changes = repo.index.diff(None, paths=paths_we_care_about)+ if uncommitted_changes:+ return True++ # Find OG AutoGPT remote+ for remote in repo.remotes:+ if remote.url.endswith(+ tuple(+ # All permutations of old/new repo name and HTTP(S)/Git URLs+ f"{prefix}{path}"+ for prefix in ("://github.com/", "[email protected]:")+ for path in (+ f"Significant-Gravitas/{n}.git" for n in ("AutoGPT", "Auto-GPT")+ )+ )+ ):+ og_remote = remote+ break+ else:+ # Original AutoGPT remote is not configured: assume local codebase diverges+ return True++ master_branch = og_remote.refs.master+ with contextlib.suppress(StopIteration):+ next(repo.iter_commits(f"HEAD..{master_branch}", paths=paths_we_care_about))+ # Local repo is one or more commits ahead of OG AutoGPT master branch+ return True++ # Relevant part of the codebase is on master+ return False+ except InvalidGitRepositoryError:+ # No git repo present: assume codebase is a clean download+ return False++def get_git_user_email() -> str:try:repo = Repo(search_parent_directories=True)