Skip to content

Commit 955d903

Browse files
committed
feat(telemetry): track binary downloads and repo clones via PostHog
Add formae_track_event helper to run-conformance-tests.sh to send ci_binary_download events after formae binary downloads. Add clone tracking step to nightly workflows and pass POSTHOG_API_KEY to conformance test steps. Gated on POSTHOG_API_KEY env var — silently no-ops when unset.
1 parent e649fbe commit 955d903

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ jobs:
139139
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
140140
FORMAE_TEST_RUN_ID: ${{ github.run_id }}-${{ github.run_attempt }}-${{ matrix.resource }}
141141
FORMAE_TEST_FILTER: ${{ matrix.resource }}
142+
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
142143
run: make conformance-test
143144

144145
# Clean up Azure resources after all matrix jobs complete

.github/workflows/nightly.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,32 @@ jobs:
9090
make build
9191
echo "FORMAE_BINARY=/tmp/formae/formae" >> $GITHUB_ENV
9292
93+
- name: Track formae clone
94+
if: env.POSTHOG_API_KEY != ''
95+
env:
96+
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
97+
run: |
98+
REPO=$(basename "$(git remote get-url origin)" .git 2>/dev/null || echo "unknown")
99+
curl -sf -o /dev/null https://us.i.posthog.com/capture/ \
100+
-H "Content-Type: application/json" \
101+
-d "$(jq -n \
102+
--arg api_key "$POSTHOG_API_KEY" \
103+
--arg repo "$REPO" \
104+
--arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
105+
--arg run_id "${GITHUB_RUN_ID:-}" \
106+
'{
107+
api_key: $api_key,
108+
distinct_id: "formae-ci",
109+
event: "ci_repo_clone",
110+
timestamp: $ts,
111+
properties: {
112+
"$process_person_profile": false,
113+
repo: $repo,
114+
cloned_repo: "formae",
115+
ci_run_id: $run_id
116+
}
117+
}')" || echo "[telemetry] event send failed (non-critical)" >&2
118+
93119
- name: Configure Azure Credentials
94120
uses: azure/login@v2
95121
with:
@@ -105,6 +131,7 @@ jobs:
105131
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
106132
FORMAE_TEST_RUN_ID: nightly-main-${{ github.run_id }}-${{ matrix.resource }}
107133
FORMAE_TEST_FILTER: ${{ matrix.resource }}
134+
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
108135
run: make conformance-test
109136

110137
# Clean up Azure resources after all matrix jobs complete

scripts/run-conformance-tests.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,45 @@ sed_inplace() {
2727
fi
2828
}
2929

30+
# Sends a telemetry event to PostHog for tracking CI/dev binary downloads.
31+
# Gated on POSTHOG_API_KEY — silently no-ops when unset.
32+
formae_track_event() {
33+
local api_key="${POSTHOG_API_KEY:-}"
34+
if [[ -z "$api_key" ]]; then return; fi
35+
36+
local event="$1"; shift
37+
local repo
38+
repo=$(basename "$(git remote get-url origin 2>/dev/null)" .git 2>/dev/null || echo "unknown")
39+
40+
local payload
41+
payload=$(jq -n \
42+
--arg api_key "$api_key" \
43+
--arg event "$event" \
44+
--arg repo "$repo" \
45+
--arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
46+
--arg run_id "${GITHUB_RUN_ID:-}" \
47+
'{
48+
api_key: $api_key,
49+
distinct_id: "formae-ci",
50+
event: $event,
51+
timestamp: $ts,
52+
properties: {
53+
"$process_person_profile": false,
54+
repo: $repo,
55+
ci_run_id: $run_id
56+
}
57+
}')
58+
59+
for kv in "$@"; do
60+
local key="${kv%%=*}" val="${kv#*=}"
61+
payload=$(echo "$payload" | jq --arg k "$key" --arg v "$val" '.properties[$k] = $v')
62+
done
63+
64+
curl -sf -o /dev/null https://us.i.posthog.com/capture/ \
65+
-H "Content-Type: application/json" \
66+
-d "$payload" || echo "[telemetry] event send failed (non-critical)" >&2 &
67+
}
68+
3069
VERSION="${1:-latest}"
3170
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
3271
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
@@ -100,6 +139,8 @@ else
100139
fi
101140
fi
102141

142+
formae_track_event "ci_binary_download" "version=${VERSION}" "os=${DETECTED_OS}" "arch=${DETECTED_ARCH}"
143+
103144
echo ""
104145
echo "Using formae binary: ${FORMAE_BINARY}"
105146
"${FORMAE_BINARY}" --version

0 commit comments

Comments
 (0)