Skip to content

Commit 6174ba4

Browse files
feat(telemetry): add CI event tracking for binary downloads and repo clones (#331)
Add a shared shell helper (scripts/ci/track-event.sh) that sends PostHog events for tracking internal formae binary downloads and repo clones. Gated on POSTHOG_API_KEY env var — silently no-ops when unset. Wire it into the Makefile fetch-external-plugins target to track plugin repo clones.
1 parent 970a095 commit 6174ba4

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ fetch-external-plugins:
5959
else \
6060
echo "Cloning $$name..."; \
6161
git clone --depth 1 $$repo "$(PLUGINS_CACHE)/$$name"; \
62+
. ./scripts/ci/track-event.sh && formae_track_event "ci_repo_clone" "cloned_repo=$$name"; \
6263
fi \
6364
done
6465
@if [ -n "$(AZURE_PLUGIN_REF)" ]; then \

scripts/ci/track-event.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
# © 2025 Platform Engineering Labs Inc.
3+
#
4+
# SPDX-License-Identifier: FSL-1.1-ALv2
5+
#
6+
# Sends telemetry events to PostHog for tracking CI/dev binary downloads and repo clones.
7+
# Gated on POSTHOG_API_KEY — if unset, silently does nothing.
8+
# Usage: source this file, then call formae_track_event "event_name" "key=value" ...
9+
10+
formae_track_event() {
11+
local api_key="${POSTHOG_API_KEY:-}"
12+
if [[ -z "$api_key" ]]; then return; fi
13+
14+
local event="$1"; shift
15+
local repo
16+
repo=$(basename "$(git remote get-url origin 2>/dev/null)" .git 2>/dev/null || echo "unknown")
17+
18+
local payload
19+
payload=$(jq -n \
20+
--arg api_key "$api_key" \
21+
--arg event "$event" \
22+
--arg repo "$repo" \
23+
--arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
24+
--arg run_id "${GITHUB_RUN_ID:-}" \
25+
'{
26+
api_key: $api_key,
27+
distinct_id: "formae-ci",
28+
event: $event,
29+
timestamp: $ts,
30+
properties: {
31+
"$process_person_profile": false,
32+
repo: $repo,
33+
ci_run_id: $run_id
34+
}
35+
}')
36+
37+
for kv in "$@"; do
38+
local key="${kv%%=*}" val="${kv#*=}"
39+
payload=$(echo "$payload" | jq --arg k "$key" --arg v "$val" '.properties[$k] = $v')
40+
done
41+
42+
curl -sf -o /dev/null https://us.i.posthog.com/capture/ \
43+
-H "Content-Type: application/json" \
44+
-d "$payload" || echo "[telemetry] event send failed (non-critical)" >&2 &
45+
}

0 commit comments

Comments
 (0)