Skip to content

750 collect stats on user and machine#788

Open
LeviXIII wants to merge 38 commits intodevfrom
750-collect-stats-on-user-and-machine
Open

750 collect stats on user and machine#788
LeviXIII wants to merge 38 commits intodevfrom
750-collect-stats-on-user-and-machine

Conversation

@LeviXIII
Copy link
Copy Markdown
Contributor

@LeviXIII LeviXIII commented Mar 23, 2026

Closes #750

Summary

Integrates PostHog analytics into both the extension host and webviews to enable telemetry, error tracking, and opt-in session recording for diagnosing user issues.

What changed

1. Extension-side PostHog telemetry (src/utils/telemetry.ts — new file)

  • Initializes posthog-node client on extension activation with system properties (OS, CPU, memory, VS Code version, extension version, locale).
  • distinctId is derived from the user's configured email, falling back to anonymous_<uuid>.
  • Exposes captureEvent, captureException, and shutdownTelemetry helpers.
  • Hooks into process.on("uncaughtException") and process.on("unhandledRejection") in extension.ts to report crashes.

2. Webview-side PostHog JS (webviews/codex-webviews/src/shared/posthog.ts — new file)

  • Reads window.__POSTHOG_CONFIG__ injected by the extension host via webviewTemplate.ts.
  • Initializes posthog-js with autocapture disabled, session recording conditionally enabled, and sensitive text masked via .ph-no-capture CSS class.
  • Registers global window.onerror and unhandledrejection listeners that forward exceptions to PostHog.

3. React ErrorBoundary (webviews/codex-webviews/src/shared/ErrorBoundary.tsx — new file)

  • Class-based error boundary wrapping every webview's root component.
  • Catches React render errors and reports them via captureException with component stack traces.
  • Shows a user-friendly "Something went wrong" fallback UI.

4. Session recording controls

  • Only the five primary webviews are recorded: CodexCellEditor, NavigationView, MainMenu, CommentsView, ParallelView. Other panels (CopilotSettings, CellLabelImporter, etc.) inject PostHog JS without recording.
  • New codex-editor-extension.sessionRecordingEnabled setting (default: true) allows users to opt out.
  • MainMenu UI exposes a toggle button with a confirmation dialog explaining what recording captures. Toggling triggers a window reload.
  • Provider-side handler in mainMenuProvider.ts reads/writes the setting and notifies the webview.

5. Sensitive text obfuscation for recordings

  • Applied ph-no-capture class to translation content areas: TextCellEditor, CellContentDisplay, ChapterNavigationHeader, MilestoneAccordion, AudioHistoryViewer.
  • Added ph-no-capture to MainMenu fields that display project metadata (project name, language info, email, etc.).

6. Misc / DX fixes

  • src/test/suite/syncManager.test.ts: Updated test to align with current sync manager API changes on the parent branch.

7. New Command to Disable

  • You can open the Command Palette and type in "Toggle Telemetry (PostHog)". You should use this when debugging.

Dependencies added

  • posthog-node (extension host — server-side telemetry)
  • posthog-js (webviews — client-side session recording & error capture)

Test plan

  • Verify extension activates and initTelemetry runs without errors (check Output panel for [Telemetry] logs)
  • Open a .codex file and confirm session recording is active in one of the five enabled webviews (PostHog dashboard should show a session)
  • Confirm translation text is masked in recordings (elements with ph-no-capture should appear redacted)
  • Open MainMenu > toggle "Disable Session Recording" — confirm dialog appears, reload occurs, and recording stops
  • Trigger a React error (e.g. bad component state) and verify it appears in PostHog as an $exception event
  • Throw an unhandled promise rejection in extension host code and verify it's captured
  • Verify non-recording webviews (e.g. CopilotSettings) do NOT start a session recording
  • Run npm run lint and npm run compile — no new errors

Fikitti and others added 28 commits March 14, 2026 18:10
Refactor mergeOriginalFilesHashes function and add comprehensive unit tests

- Changed the mergeOriginalFilesHashes function to be exported for external use.
- Introduced a new test suite for mergeOriginalFilesHashes, covering various scenarios including handling undefined inputs, merging entries with different hashes, and deduplicating referencedBy and originalNames.
- Ensured that version numbers are correctly managed and that fileNameToHash is built accurately from merged entries.
…-mergeoriginalfileshashes

Added a resolver test for merging Original file hashes
When a project has a pinnedExtension for codex-editor, updateExtensionVersions
now skips the codexEditor floor bump. This prevents the version gate from
blocking collaborators who are intentionally running a pinned (older) version
after the project was last opened on a newer build.

frontierAuthentication ratcheting is unaffected.
Tests were disabled in aabd942 during a MetadataManager refactor with no
specific failure documented. All existing tests pass cleanly in the current
VS Code test environment.

Adds three new cases to cover the pin-aware ratchet behaviour introduced
in the previous commit: no-pin (ratchet works normally), codex-editor pin
active (codexEditor bump suppressed), and frontier pin irrelevance
(frontierAuthentication still ratchets when codex-editor is pinned).
Both codexEditor and frontierAuthentication ratchet checks now read from
meta.pinnedExtensions (keyed by extension id) instead of the old singular
meta.pinnedExtension object. Updates test fixtures to match.
On Windows, fs.writeFile can resolve before the written bytes are
visible to a subsequent read, causing readFile to return empty content
from a file that stat reports as non-empty. The function already
retried on transient EntryNotFound errors; extend the same 25 ms retry
loop to cover this empty-content case so callers are not spuriously
blocked from saving.
One test in the search/replace suite was using a bare JSON.parse on a
direct readFile call instead of the existing readJsonFromDiskWithRetry
helper, making it susceptible to the same Windows filesystem flush
timing flakiness that the helper was introduced to guard against.
Update ratchet suppression to use publisher.name format
(e.g. 'project-accelerate.codex-editor-extension') instead of
short names. Aligns with conductor's metadata.json key format.
auto-tag.yml now builds a VSIX and creates a GitHub Release on version
bump. New pr-vsix.yml creates pre-releases for PR builds, with
workflow_dispatch for manual testing.
- Adjust some of the posthog config to only use Identify event and usernames plus a random uuid.
Adds the full pinnedExtensions shape (version, url, reason, expiry,
setBy) to the shared ProjectMetadata in types/index.d.ts so other
parts of the codebase can use it without defining ad-hoc types.
Remove reason, expiry, and setBy fields — setBy is covered by git
blame, expiry and reason are unnecessary complexity.
Align both ratchet-suppression methods to use existence checks for pins
and consolidate ensureExtensionVersionsRecorded to a single metadata read.
@LeviXIII LeviXIII linked an issue Mar 23, 2026 that may be closed by this pull request
@LeviXIII LeviXIII changed the base branch from main to dev March 24, 2026 13:39
@BenjaminScholtens BenjaminScholtens changed the base branch from dev-old to dev March 27, 2026 16:31
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.

Collect stats on user and machine.

5 participants