From e1027fbe8f5eb6e92a3354fd55a31a8688c24984 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Fri, 24 Jul 2026 16:46:42 +0300 Subject: [PATCH] Track codespace create/start events via Cloud Function Add .devcontainer/track.sh, a best-effort curl that POSTs a codespace lifecycle event to an HTTP Google Cloud Function which logs it to MongoDB Atlas. Wire it into postCreateCommand (created) and postStartCommand (started); both use || true so telemetry never breaks the environment. --- .devcontainer/devcontainer.json | 4 ++-- .devcontainer/track.sh | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .devcontainer/track.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 69b0f5f..d6876f4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -31,8 +31,8 @@ "label": "MongoDB" } }, - "postCreateCommand": "npm install", - "postStartCommand": "bash -lc 'for i in {1..60}; do mongosh --quiet \"$DATABASE_URI\" --eval \"db.hello().isWritablePrimary\" | grep -q true && break; sleep 2; done; npm run seed'", + "postCreateCommand": "npm install && bash .devcontainer/track.sh created || true", + "postStartCommand": "bash -lc 'for i in {1..60}; do mongosh --quiet \"$DATABASE_URI\" --eval \"db.hello().isWritablePrimary\" | grep -q true && break; sleep 2; done; npm run seed; bash .devcontainer/track.sh started || true'", "remoteEnv": { "DATABASE_URI": "mongodb://localhost:27017/meanStackExample?appName=mean-stack-example-devcontainer" } diff --git a/.devcontainer/track.sh b/.devcontainer/track.sh new file mode 100644 index 0000000..53caec3 --- /dev/null +++ b/.devcontainer/track.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +# Best-effort telemetry: log a codespace lifecycle event. Never fails the caller. +EVENT="${1:-unknown}" +URL="https://us-central1-project-learning-fuel.cloudfunctions.net/trackCodespace" +curl -fsS -m 5 -X POST "$URL" \ + -H "Content-Type: application/json" \ + -d "{\"event\":\"$EVENT\",\"codespace\":\"${CODESPACE_NAME:-}\",\"user\":\"${GITHUB_USER:-}\",\"repository\":\"${GITHUB_REPOSITORY:-mongodb-developer/mean-stack-example}\"}" \ + >/dev/null 2>&1 || true