Skip to content

feat(telemetry): stitch CLI identity from API response header#5054

Merged
seanoliver merged 4 commits intodevelopfrom
sean/cli-identity-stitching
Apr 9, 2026
Merged

feat(telemetry): stitch CLI identity from API response header#5054
seanoliver merged 4 commits intodevelopfrom
sean/cli-identity-stitching

Conversation

@seanoliver
Copy link
Copy Markdown
Contributor

@seanoliver seanoliver commented Apr 8, 2026

Summary

  • Adds an identityTransport RoundTripper that reads X-Gotrue-Id from management API response headers
  • When the header is present and the device hasn't been identified yet, calls existing StitchLogin() to link device_idgotrue_id in PostHog
  • One-time per device, cached in telemetry.json after first stitch

Companion PR: supabase/platform#31378 — platform-side interceptor that sets the X-Gotrue-Id response header. Safe to merge in either order; without the header, this change is a transparent no-op.

Context: GROWTH-756 — ~89% of CLI devices are anonymous. CLI tokens are opaque (sbp_*), so gotrue_id can't be extracted locally. This piggybacks on existing API calls to passively resolve identity, taking coverage from 11% → ~85%.

Test plan

  • go test ./internal/utils/ -run TestIdentityTransport -v — transport captures header when present, ignores when absent
  • go test ./internal/telemetry/ -run TestServiceNeedsIdentityStitch -v — returns true when DistinctID empty, false after stitch
  • go test ./... — no regressions
  • Manual: run any authenticated command with DEBUG=true — confirms no errors (header not present yet, so no stitch attempt)

@seanoliver seanoliver requested a review from a team as a code owner April 8, 2026 20:43
@coveralls
Copy link
Copy Markdown

coveralls commented Apr 8, 2026

Coverage Report for CI Build 24205885789

Warning

No base build found for commit e5fdfe9 on develop.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 63.794%

Details

  • Patch coverage: 8 uncovered changes across 1 file (17 of 25 lines covered, 68.0%).

Uncovered Changes

File Changed Covered %
cmd/root.go 8 0 0.0%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 15354
Covered Lines: 9795
Line Coverage: 63.79%
Coverage Strength: 7.01 hits per line

💛 - Coveralls

Copy link
Copy Markdown
Member

@avallete avallete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpicks, nothing blocking.

…ests

- Wrap StitchLogin callback in sync.Once to prevent duplicate $alias
  calls if concurrent API responses both carry X-Gotrue-Id
- Rename HeaderGotrueId → HeaderGotrueID per Go naming conventions
- Add tests for nil callback and inner transport error paths
Avoids capturing OnGotrueID by value at GetSupabase() init time, which
would silently hold nil if clientOnce.Do ran before PersistentPreRunE
set the callback. Transport now holds &OnGotrueID and dereferences at
call time, decoupling initialization order.
@seanoliver seanoliver force-pushed the sean/cli-identity-stitching branch from 271bcc9 to a271d96 Compare April 9, 2026 18:10
@seanoliver seanoliver merged commit 47426cd into develop Apr 9, 2026
10 checks passed
@seanoliver seanoliver deleted the sean/cli-identity-stitching branch April 9, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants