aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Reinier van der Leer <pwuts@agpt.co> 2024-02-15 16:00:30 +0100
committerGravatar Reinier van der Leer <pwuts@agpt.co> 2024-02-15 16:00:30 +0100
commitfd5730b04aed8b60d639a6a6b067e64d2a8f7278 (patch)
tree55694fce7501a2f1e42466ebf17ba09a9720099e
parentfeat(agent/telemetry): Enable performance tracing & update opt-in prompt acco... (diff)
downloadAuto-GPT-fd5730b04aed8b60d639a6a6b067e64d2a8f7278.tar.gz
Auto-GPT-fd5730b04aed8b60d639a6a6b067e64d2a8f7278.tar.bz2
Auto-GPT-fd5730b04aed8b60d639a6a6b067e64d2a8f7278.zip
feat(agent/telemetry): Distinguish between `production` and `dev` environment based on VCS state
- Added a helper function `.app.utils.vcs_state_diverges_from_master()`. This function determines whether the relevant part of the codebase diverges from our `master`. - Updated `.app.telemetry._setup_sentry()` to determine the default environment name using `vcs_state_diverges_from_master`.
-rw-r--r--autogpts/autogpt/autogpt/app/telemetry.py12
-rw-r--r--autogpts/autogpt/autogpt/app/utils.py45
2 files changed, 55 insertions, 2 deletions
diff --git a/autogpts/autogpt/autogpt/app/telemetry.py b/autogpts/autogpt/autogpt/app/telemetry.py
index d89e4e6c7..9706781d7 100644
--- a/autogpts/autogpt/autogpt/app/telemetry.py
+++ b/autogpts/autogpt/autogpt/app/telemetry.py
@@ -3,7 +3,12 @@ import os
import click
from 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", # noqa
enable_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 users
diff --git a/autogpts/autogpt/autogpt/app/utils.py b/autogpts/autogpt/autogpt/app/utils.py
index 5a2757161..7b815e2c7 100644
--- a/autogpts/autogpt/autogpt/app/utils.py
+++ b/autogpts/autogpt/autogpt/app/utils.py
@@ -1,3 +1,4 @@
+import contextlib
import logging
import os
import 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/", "git@github.com:")
+ 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)