Skip to content

feat: add anonymous telemetry and error tracking#135

Merged
rhuanbarreto merged 13 commits into
mainfrom
feat/telemetry
Mar 22, 2026
Merged

feat: add anonymous telemetry and error tracking#135
rhuanbarreto merged 13 commits into
mainfrom
feat/telemetry

Conversation

@rhuanbarreto

@rhuanbarreto rhuanbarreto commented Mar 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add anonymous usage analytics via PostHog HTTP API (no SDK — just fetch())
  • Add error tracking via Sentry HTTP envelope API (no SDK — just fetch())
  • Add archgate telemetry [status|enable|disable] command
  • Add first-run telemetry notice (one-time, to stderr)
  • Add telemetry docs page with full privacy policy (EN + pt-BR)
  • IP anonymization: PostHog resolves country/region server-side, then discards IP
  • Opt-out via ARCHGATE_TELEMETRY=0 env var or archgate telemetry disable
  • Zero new production dependencies (ARCH-006 compliant)

Key design decisions

  • Opt-out model — telemetry enabled by default, no consent prompt
  • PostHog for analytics — start on free tier, migrate to custom service later if needed
  • Sentry HTTP API (not SDK) — keeps binary lean, no added deps
  • Coarse geolocation — country/region only, no IP stored
  • Fire-and-forget — all network calls are non-blocking, failures silently ignored
  • Placeholder API keys — DSN/API keys need to be replaced with real values before release

Files added

File Purpose
src/helpers/telemetry-config.ts Config persistence in ~/.archgate/config.json
src/helpers/telemetry.ts PostHog event tracking via HTTP API
src/helpers/sentry.ts Sentry error capture via HTTP envelope API
src/helpers/telemetry-notice.ts One-time first-run notice
src/commands/telemetry.ts archgate telemetry command
tests/helpers/telemetry*.test.ts Tests for all telemetry modules
tests/helpers/sentry.test.ts Tests for Sentry module
docs/.../reference/telemetry.mdx Privacy/telemetry docs (EN + pt-BR)

Test plan

  • bun run validate passes (lint, typecheck, format, 492 tests, 21/21 ADR checks, build)
  • Replace placeholder PostHog API key and verify events appear in PostHog dashboard
  • Replace placeholder Sentry DSN and verify error events appear in Sentry
  • Test opt-out: ARCHGATE_TELEMETRY=0 prevents all network calls
  • Test archgate telemetry disable persists to config and stops tracking
  • Verify first-run notice appears once then never again
  • Verify no performance regression on CLI startup

rhuanbarreto and others added 2 commits March 22, 2026 02:11
Add opt-out telemetry via PostHog HTTP API and error tracking via Sentry
HTTP envelope API — no SDK dependencies added (ARCH-006 compliant).

- PostHog analytics: command usage, flags, exit codes, duration, coarse geo
- Sentry error capture: crash reports with stack traces for exit-code-2 errors
- IP anonymization: PostHog resolves geo server-side then discards IP
- Opt-out: ARCHGATE_TELEMETRY=0 env var or `archgate telemetry disable`
- First-run notice: one-time stderr message about data collection
- Telemetry command: status/enable/disable subcommands
- Docs: telemetry reference page (EN + pt-BR) with full privacy policy
- Tests: telemetry-config, telemetry, sentry, telemetry-notice
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 22, 2026

Copy link
Copy Markdown

Deploying archgate-cli with  Cloudflare Pages  Cloudflare Pages

Latest commit: 72e6d72
Status: ✅  Deploy successful!
Preview URL: https://5efde030.archgate-cli.pages.dev
Branch Preview URL: https://feat-telemetry.archgate-cli.pages.dev

View logs

rhuanbarreto and others added 11 commits March 22, 2026 02:15
Add proper Portuguese diacritical marks (ã, é, ê, ç, í, ó, ú, etc.)
throughout the pt-BR telemetry docs page.
Telemetry is documented in the docs site instead of showing a CLI notice.
Use the official Sentry SDK for breadcrumbs and distributed tracing.
- Breadcrumbs track command execution flow for crash context
- Tracing propagated to plugins.archgate.dev via sentry-trace headers
- addBreadcrumb() exported for use across CLI modules
- flushSentry() ensures events are sent before process exit
…tags

- install_method: binary, proto, local, or package-manager
- install_path: process.execPath for debugging platform-specific issues
- release: set to plain version string (e.g., "0.17.2")
…n.env

- New ADR ARCH-014 with automated rule no-process-env
- Replace all process.env references in src/ with Bun.env
- Replace require("package.json") with static import (bundled at compile)
- Remove unnecessary typeof Bun guards (CLI only runs on Bun)
Use the official PostHog Node SDK for event capture with automatic
batching, retry, and flush. Adds timeout to shutdown to prevent
hanging on exit. Integration test harness disables telemetry via
ARCHGATE_TELEMETRY=0 to prevent SDK event loops from holding the
subprocess open.
Use Sentry's lightweight "light" variant which excludes all OpenTelemetry
auto-instrumentation (600+ modules of OTel for MongoDB, Redis, Express,
Kafka, etc.). The light mode provides error capture + breadcrumbs which
is all a CLI needs.

Binary size impact: 0 MB increase (was +10 MB with @sentry/bun).
Module count: 434 (same as baseline, was 1,129 with @sentry/bun).
…ntime name

- install_path: use Bun.main (entry script) instead of process.execPath
  (which returns the bun binary, e.g. .proto/tools/bun/1.3.11/bun.exe)
- runtime: filter out NodeContext integration which overrides our
  runtime context with "node" — we set it explicitly to "bun"
- install_method detection also uses archgate path instead of bun path
PostHog signup not available yet. The telemetry module and posthog-node
dependency are kept for when PostHog is ready — just not wired into
cli.ts. Sentry error tracking remains active.

Also fixes cli.ts telemetry integration that was accidentally reverted
during the binary size comparison.
@rhuanbarreto rhuanbarreto merged commit fadfcb1 into main Mar 22, 2026
11 of 14 checks passed
@rhuanbarreto rhuanbarreto deleted the feat/telemetry branch March 22, 2026 02:44
@github-actions github-actions Bot mentioned this pull request Mar 22, 2026
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.

1 participant