[eric] analytics: opt-in dev telemetry (OPENSWARM_ANALYTICS=1) tagged with a -dev channel

This commit is contained in:
ciregenz
2026-07-19 11:18:58 -07:00
parent 6652309f42
commit a41e9699a5
3 changed files with 29 additions and 12 deletions
+16 -12
View File
@@ -10,18 +10,22 @@ import os
def read_app_version() -> str:
# Preferred: Electron's main process injects this when spawning the backend (see electron/main.js; OPENSWARM_APP_VERSION). Always reliable in packaged builds because it comes from app.getVersion() rather than path-based file resolution.
env_v = os.environ.get("OPENSWARM_APP_VERSION", "").strip()
if env_v:
return env_v
# Fallback: read electron/package.json via relative path. Works in `bash run.sh` dev mode where the repo layout is intact, but FAILS in packaged dmg/exe builds because electron/package.json isn't shipped into Resources/; which made every shipped install report app_version="unknown" pre-fix. Kept for backward compatibility with dev runs and as a safety net if the env var is ever unset.
try:
p_here = os.path.dirname(os.path.abspath(__file__))
p_repo = os.path.dirname(os.path.dirname(os.path.dirname(p_here)))
p_pkg = os.path.join(p_repo, "electron", "package.json")
with open(p_pkg, encoding="utf-8") as p_f:
return json.load(p_f).get("version", "unknown")
except (OSError, ValueError, KeyError):
return "unknown"
base = os.environ.get("OPENSWARM_APP_VERSION", "").strip()
if not base:
# Fallback: read electron/package.json via relative path. Works in `bash run.sh` dev mode where the repo layout is intact, but FAILS in packaged dmg/exe builds because electron/package.json isn't shipped into Resources/; which made every shipped install report app_version="unknown" pre-fix. Kept for backward compatibility with dev runs and as a safety net if the env var is ever unset.
try:
p_here = os.path.dirname(os.path.abspath(__file__))
p_repo = os.path.dirname(os.path.dirname(os.path.dirname(p_here)))
p_pkg = os.path.join(p_repo, "electron", "package.json")
with open(p_pkg, encoding="utf-8") as p_f:
base = json.load(p_f).get("version", "unknown")
except (OSError, ValueError, KeyError):
base = "unknown"
# A dev/hackathon cohort (OPENSWARM_APP_CHANNEL=dev) reports e.g. "1.5.8-dev" so its events stay filterable from real installs; prod or unset keeps the bare version.
channel = os.environ.get("OPENSWARM_APP_CHANNEL", "").strip().lower()
if channel and channel != "prod":
return f"{base}-{channel}"
return base
APP_VERSION = read_app_version()
+6
View File
@@ -99,6 +99,12 @@ function Cleanup-All {
Write-Host "All services stopped." -ForegroundColor Green
}
# Opt-in dev telemetry: OPENSWARM_ANALYTICS=1 reports to the prod edge tagged with a -dev channel so it stays filterable from real installs; off by default so a stray run never phones home.
if ($env:OPENSWARM_ANALYTICS -eq '1') {
if (-not $env:OPENSWARM_ANALYTICS_URL) { $env:OPENSWARM_ANALYTICS_URL = 'https://analytics.openswarm.com' }
if (-not $env:OPENSWARM_APP_CHANNEL) { $env:OPENSWARM_APP_CHANNEL = 'dev' }
}
try {
# --- Start backend (NoNewWindow so logs interleave into this terminal) ---
# No --reload on Windows: uvicorn's reload mode forces use_subprocess=True
+7
View File
@@ -103,6 +103,13 @@ fi
# directly), so the env stays unset in production and uvicorn boots in
# its leaner non-reload mode.
export OPENSWARM_DEV=1
# Opt-in dev telemetry. Dev normally never reports (the analytics client falls back to a dead local ingest); set OPENSWARM_ANALYTICS=1 (e.g. a hackathon cohort) to report to the prod edge, tagged with a -dev channel so those events stay filterable from real installs. Off by default so a stray `bash run.sh` never phones home.
if [ "${OPENSWARM_ANALYTICS:-0}" = "1" ]; then
export OPENSWARM_ANALYTICS_URL="${OPENSWARM_ANALYTICS_URL:-https://analytics.openswarm.com}"
export OPENSWARM_APP_CHANNEL="${OPENSWARM_APP_CHANNEL:-dev}"
fi
echo -e "${BLUE}${BOLD}[backend]${RESET} Starting backend server..."
bash "$PROJECT_ROOT/backend/run.sh" > >(
while IFS= read -r line; do