feat(telemetry): attach org/project groups to all CLI events#5087
Open
seanoliver wants to merge 2 commits intodevelopfrom
Open
feat(telemetry): attach org/project groups to all CLI events#5087seanoliver wants to merge 2 commits intodevelopfrom
seanoliver wants to merge 2 commits intodevelopfrom
Conversation
Only ~19% of CLI events had PostHog group properties ($group_0, $group_1) because groups were only set during `supabase link`. Commands using --project-ref without linking sent events invisible to group analytics. Add EnsureProjectGroupsCached which resolves and caches project metadata (including org ID) in linked-project.json when a project ref is available. The cache is checked before every cli_command_executed event, so the API call only happens once per unique project ref. Closes GROWTH-761
- Guard against log.Fatalln crash: check auth token before calling GetSupabase(), and move the API call to cmd/root.go where it belongs - Don't overwrite existing linked-project.json cache — supabase link is the authoritative source, we only fill the gap when no cache exists - Fire GroupIdentify for org and project after caching, matching the link flow so PostHog has group metadata - Restructure so telemetry package has no API dependencies (pure caching + PostHog calls), making tests reliable without gock/mocks
Coverage Report for CI Build 24479669207Coverage decreased (-0.09%) to 63.66%Details
Uncovered Changes
Coverage Regressions5 previously-covered lines in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Only ~19% of CLI events have PostHog group properties set (
$group_0for org,$group_1for project). Groups are only written duringsupabase link, so any command using--project-refwithout linking first sends events that are invisible to PostHog group analytics. This means we can't filter or aggregate ~80% of CLI activity by org or project.Back in early April when CLI telemetry shipped, the plumbing for groups was built out (the
CommandContext.Groupsfield,mergeGroups()layering,linkedProjectGroups()reader) but only the link flow actually populates the cache.Changes
EnsureProjectGroupsCached()ininternal/telemetry/project.go— when a project ref is available but no matchinglinked-project.jsonexists, fetches the project from the management API and caches it. Subsequent commands with the same ref skip the API call entirely.Execute()incmd/root.goright before firingcli_command_executed, so the existinglinkedProjectGroups()reader picks up the cached data.Testing
go test ./internal/telemetry/... -v)go build ./...)V1ProjectWithDatabaseResponse) matches whatSaveLinkedProjectexpectsCloses GROWTH-761