-
feat(cli): send telemetry direct to PostHog; stitch install→Apollo identity (#3927)
发布于
2026-07-30 18:37:31 +00:00 What
Sends CLI telemetry directly to PostHog (project 196278) instead of
through Apollo/Segment, and stitches the anonymous install identity to
the Apollo user at login. This unlocks the previously-dark top of the
CLI adoption funnel (install → setup → login → connect → execute).Why
Two live funnel breaks in PostHog today:
- Install/setup/plugin events were dark. Pre-login,
dispatch.ts
had no API base URL (→ endpoint null → dropped), and Apollo's ingest
401s anonymous requests. SoCLI_INSTALL_*/CLI_SETUP_*never arrived. - Identity split. CLI/server events landed on email-keyed PostHog
persons (via Segment); dashboard onboarding on UUID-keyed persons —
the two never joined.
The CLI already knows the canonical Apollo UUID (
org_member.idfrom
session info), so it can self-stitch with no platform/dashboard change.How
- Direct transport. New PostHog capture path (
captureToPostHog)
reusing the existing detached best-effort worker. No dependency on the
API base URL, so pre-login events send. - Identity. Pre-login
distinct_id = install_id; at login
linkApolloIdentityForAnalytics(org_member.id)persists the UUID to
~/.composio/analytics.jsonand fires one$create_alias(install_id → org_member.id); post-login events key on the persisted
apollo_user_id. Because onboarding is already UUID-keyed, the CLI
funnel now joins web onboarding. - Public key, baked at build. The write-only
phc_project key is
injected viabun build --definefrom theCOMPOSIO_POSTHOG_KEYenv
(CI Actions variable), never committed to source.--define(not a
second--env) is deliberate — Bun honors only the last--env, which
would clobber the existingDEBUG_OVERRIDE_*bake. For this OSS repo
this keeps the key out of git history and means forks / local builds
compile a no-op binary (only official releases carry the key). - Direct-only: the Apollo
/cli/analyticssend is dropped for CLI
events; the CLI attaches its ownorg_id(project_id is per-session; a
follow-up).
Guards
No-op (no send, no worker spawn, no identity-file write) when telemetry
is disabled
(COMPOSIO_CLI_TELEMETRY_DISABLED/TELEMETRY_DISABLED/COMPOSIO_DISABLE_TELEMETRY/CI/NODE_ENV=test)
or when no project key is configured. Alias fires once per install
(idempotent). No user API key or tool-arg values in event properties.Verification
pnpm typecheck,validate:boundaries, full CLI vitest (954 passed
/ 1 skipped) — green.- Independent code review pass; findings addressed (spawn-gated-on-key,
disabled=no-file, idempotent alias). - Live cold-install trace: built the real compiled binary with the
key baked, ran it from a throwaway$HOME→ freshinstall_id→ 2
pre-login events delivered tous.i.posthog.comwith HTTP 200 →
confirmed queryable in PostHog 196278 within ~10s, keyed by
install_id.
Notes
- CLI is Changesets-ignored; human note added to
CHANGELOG.md
directly. - Requires the
COMPOSIO_POSTHOG_KEYActions variable to be set for
official release builds (done).
🤖 Generated with Claude Code
下载附件
- Install/setup/plugin events were dark. Pre-login,