You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(cli): eagerly resolve TelemetryClient distinctId via async factory (#14748)
## Description
Part of the CLI error classification effort — see #14749 for full context.
Makes telemetry synchronous in **CLI v2** by eagerly resolving the PostHog `distinctId` at startup via an async factory, so that `Context.telemetry` becomes a synchronous `TelemetryClient`. This is the CLI v2 counterpart to #14747 (CLI v1).
## Why
Same motivation as #14747: the new error system (#14749) introduces a `reportError` function called from `failWithoutThrowing` and top-level catch blocks. This function needs synchronous access to telemetry to capture Sentry exceptions with PostHog correlation. Previously `Context.telemetry` was a `Promise<TelemetryClient>`, which forced all error handlers to be async. Moving the async resolution to startup keeps the hot path simple and avoids changing the `TaskContext` interface.
## Changes Made
- Added `TelemetryClient.create()` async factory that resolves `distinctId` eagerly
- `Context.telemetry` is now a synchronous `TelemetryClient` (no more `Promise<TelemetryClient>`)
- Updated all test helpers to use the new factory (`TelemetryClient.create()` or direct construction)
- Adjusted CLI v2 `withContext` to `await` telemetry creation at startup
## Testing
- [x] Updated TelemetryClient tests for new factory pattern
- [x] Updated test context helpers
0 commit comments