spawn/packages
Ahmed Abushagur cd3537c051
fix(telemetry): send events immediately — no more lost funnel data (#3339)
* fix(telemetry): send events immediately, persistent user ID, session continuity

Root cause: events were batched (threshold: 10) but orchestration only fires
~8 funnel events. process.exit() kills the process before beforeExit flushes.
Zero real funnel events ever reached PostHog.

Fixes:
- Send each event immediately via fetch (no batching, no lost events)
- Persistent user ID in ~/.config/spawn/.telemetry-id (same across all runs)
- Session ID inherited via SPAWN_TELEMETRY_SESSION env var (parent → child)
- source: "cli" on every event (filter from website data in PostHog)

Removed: _events array, _flushScheduled, flush(), flushSync(), batch logic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(telemetry): remove process.exit(0) so telemetry fetches complete

process.exit(0) was called immediately after main() resolved, aborting
any in-flight fire-and-forget telemetry fetches. This silently dropped
spawn_deleted, funnel, and lifecycle events. Now the process exits
naturally when the event loop drains, giving pending requests time to
complete.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: A <258483684+la14-1@users.noreply.github.com>
2026-04-22 00:28:33 -07:00
..
cli fix(telemetry): send events immediately — no more lost funnel data (#3339) 2026-04-22 00:28:33 -07:00
shared fix: rethrow normalized Error in tryCatchIf/asyncTryCatchIf (#2930) 2026-03-23 19:33:05 -07:00