-
Notifications
You must be signed in to change notification settings - Fork 34
feat: add anonymous CLI telemetry via PostHog #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
648a73a
feat: add anonymous CLI telemetry via PostHog
felipefreitag 35c3b86
refactor: rename telemetry event to cli.used
felipefreitag da96118
refactor: replace is_ci/json_mode with interactive flag
felipefreitag 3b68feb
feat: deliver telemetry via detached self-invocation for zero latency
felipefreitag 636ad3f
refactor: harden telemetry delivery and simplify payload
felipefreitag 94c4be5
fix: make telemetry test OS-agnostic for CI compatibility
felipefreitag 580fe1d
fix: handle pkg compiled binary in telemetry self-invocation
felipefreitag 4d4e51a
feat: inject PostHog key at build time via esbuild define
felipefreitag c27e44d
feat: track explicitly-passed flag names in telemetry
felipefreitag 714b701
fix: set PKG_EXECPATH for pkg binary self-invocation
felipefreitag 239c95b
ci: add Windows telemetry smoke test workflow
felipefreitag 2b7b54e
fix: harden telemetry against review findings
felipefreitag c0d91a1
fix: harden telemetry against review findings
felipefreitag f2c1f52
ci: fix Windows telemetry test with PowerShell
felipefreitag 5ba457b
fix: strip surrounding quotes from .env values in build script
felipefreitag c0ad46b
ci: verify temp file creation before checking consumption
felipefreitag 589b5e2
fix: only write notice marker when notice is actually shown
felipefreitag 6d36159
ci: fix PowerShell syntax in Windows telemetry test
felipefreitag b244f42
ci: remove push trigger from Windows telemetry test
felipefreitag d36410d
refactor: distinguish install-script from manual installs in detection
felipefreitag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: Test Telemetry (Windows) | ||
| on: | ||
| workflow_dispatch: | ||
| jobs: | ||
| test: | ||
| runs-on: windows-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: pnpm/action-setup@v4 | ||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 24 | ||
| cache: 'pnpm' | ||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
| - name: Build Node bundle | ||
| run: pnpm build | ||
| env: | ||
| POSTHOG_PUBLIC_KEY: ${{ secrets.POSTHOG_STAGING_KEY }} | ||
| - name: Build Windows binary | ||
| run: pnpm exec pkg dist/cli.cjs --compress Brotli --target node24-win-x64 --output dist/resend.exe | ||
| - name: Test telemetry spawn from binary | ||
| run: | | ||
| $tmpdir = [System.IO.Path]::GetTempPath() | ||
|
|
||
| # Clear leftover telemetry files | ||
| Remove-Item "$tmpdir\resend-telemetry-*.json" -ErrorAction SilentlyContinue | ||
|
|
||
| # Run a real command that triggers telemetry | ||
| dist/resend.exe --api-key re_fake whoami | ||
| Write-Host "Binary exited with code $LASTEXITCODE" | ||
|
|
||
| # Verify the temp file WAS created | ||
| Start-Sleep -Seconds 1 | ||
| $created = Get-ChildItem "$tmpdir\resend-telemetry-*.json" -ErrorAction SilentlyContinue | ||
| if (-not $created) { | ||
| Write-Host "::error::Telemetry temp file was never created — trackCommand did not fire" | ||
| exit 1 | ||
| } | ||
| Write-Host "Temp file created: $($created.FullName)" | ||
|
|
||
| # Give the detached child time to flush | ||
| Start-Sleep -Seconds 10 | ||
|
|
||
| # Verify the temp file was consumed by the child | ||
| $remaining = Get-ChildItem "$tmpdir\resend-telemetry-*.json" -ErrorAction SilentlyContinue | ||
| if ($remaining) { | ||
| Write-Host "::error::Telemetry temp file was not consumed — detached self-spawn failed" | ||
| $remaining | Format-Table Name, Length, LastWriteTime | ||
| exit 1 | ||
| } | ||
| Write-Host "Telemetry spawn OK — file created and consumed by child process" | ||
| - name: How to verify the event | ||
| if: always() | ||
| run: | | ||
| Write-Host "Check the staging PostHog project for a 'cli.used' event with:" | ||
| Write-Host " command: whoami" | ||
| Write-Host " os: Windows" | ||
| Write-Host " install_method: other" |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
| import { build } from 'esbuild'; | ||
|
|
||
| function loadDotenv() { | ||
| try { | ||
| const content = readFileSync('.env', 'utf8'); | ||
| for (const line of content.split('\n')) { | ||
| const match = line.match(/^\s*([^#=]+?)\s*=\s*(.*?)\s*$/); | ||
| if (match) { | ||
| process.env[match[1]] ??= match[2].replace(/^(['"])(.*)\1$/, '$2'); | ||
| } | ||
| } | ||
| } catch {} | ||
| } | ||
|
|
||
| loadDotenv(); | ||
|
|
||
| const posthogKey = process.env.POSTHOG_PUBLIC_KEY ?? ''; | ||
|
|
||
| await build({ | ||
| entryPoints: ['src/cli.ts'], | ||
| bundle: true, | ||
| platform: 'node', | ||
| format: 'cjs', | ||
| minify: true, | ||
| outfile: 'dist/cli.cjs', | ||
| define: { | ||
| 'process.env.POSTHOG_PUBLIC_KEY': JSON.stringify(posthogKey), | ||
| }, | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { readFileSync } from 'node:fs'; | ||
|
|
||
| const bundle = readFileSync('dist/cli.cjs', 'utf8'); | ||
|
|
||
| if (!bundle.includes('phc_')) { | ||
| console.error( | ||
| 'Error: POSTHOG_PUBLIC_KEY not found in bundle — add it to .env', | ||
| ); | ||
| process.exit(1); | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.