Skip to content

Commit f068f1a

Browse files
committed
Add Codespace lifecycle telemetry tracking
Replicates the tracking setup from mongodb-developer/mean-stack-example: .devcontainer/track.sh plus postCreateCommand/postStartCommand hooks that best-effort report created/started events to the shared codespace-telemetry function. Appended with || true so telemetry can never break the dev environment.
1 parent e08342a commit f068f1a

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎.devcontainer/devcontainer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"DB_URL": "mongodb://localhost:27017/",
3030
"DB_NAME": "farm_intro"
3131
},
32-
"postCreateCommand": "pip install -r backend/requirements.txt && cd frontend && npm ci",
33-
"postStartCommand": "echo 'Services ready: MongoDB local on 27017. Backend and frontend start automatically after attach.'",
32+
"postCreateCommand": "pip install -r backend/requirements.txt && cd frontend && npm ci && bash /workspaces/FARM-Intro/.devcontainer/track.sh created || true",
33+
"postStartCommand": "echo 'Services ready: MongoDB local on 27017. Backend and frontend start automatically after attach.'; bash /workspaces/FARM-Intro/.devcontainer/track.sh started || true",
3434
"postAttachCommand": {
3535
"backend": "cd backend && DEBUG_MODE=true uvicorn main:app --host 0.0.0.0 --port 8000 --reload",
3636
"frontend": "cd frontend && HOST=0.0.0.0 npm start"

‎.devcontainer/track.sh‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
# Best-effort telemetry: log a codespace lifecycle event. Never fails the caller.
3+
EVENT="${1:-unknown}"
4+
GIT_EMAIL="$(git config --get user.email 2>/dev/null || true)"
5+
URL="https://us-central1-project-learning-fuel.cloudfunctions.net/trackCodespace"
6+
curl -fsS -m 5 -X POST "$URL" \
7+
-H "Content-Type: application/json" \
8+
-d "{\"event\":\"$EVENT\",\"codespace\":\"${CODESPACE_NAME:-}\",\"user\":\"${GITHUB_USER:-}\",\"gitEmail\":\"${GIT_EMAIL:-}\",\"repository\":\"${GITHUB_REPOSITORY:-mongodb-developer/FARM-Intro}\"}" \
9+
>/dev/null 2>&1 || true

0 commit comments

Comments
 (0)