Skip to content

Commit 71bb33d

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 b873121 commit 71bb33d

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
@@ -28,8 +28,8 @@
2828
}
2929
},
3030

31-
"postCreateCommand": "cd mern/server && npm ci && cd ../client && npm ci",
32-
"postStartCommand": "bash .devcontainer/startup.sh",
31+
"postCreateCommand": "cd mern/server && npm ci && cd ../client && npm ci && bash /workspaces/mern-stack-example/.devcontainer/track.sh created || true",
32+
"postStartCommand": "bash .devcontainer/startup.sh; bash /workspaces/mern-stack-example/.devcontainer/track.sh started || true",
3333

3434
// this will open 3 bash sessions, each one running the specified command
3535
"postAttachCommand": {

.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/mern-stack-example}\"}" \
9+
>/dev/null 2>&1 || true

0 commit comments

Comments
 (0)