Skip to content

feat(error-tracking): PostHog autocapture + sourcemap upload#35

Merged
AquiGorka merged 2 commits into
mainfrom
posthog-error-tracking
May 28, 2026
Merged

feat(error-tracking): PostHog autocapture + sourcemap upload#35
AquiGorka merged 2 commits into
mainfrom
posthog-error-tracking

Conversation

@AquiGorka
Copy link
Copy Markdown
Contributor

Summary

  • Wires PostHog exception autocapture + manual captureException into the existing src/lib/analytics.ts (analytics-event capture is untouched).
  • Production build flips sourcemap: !isProductionsourcemap: true so app.js.map is emitted next to the bundle.
  • deploy.yml (testnet + mainnet) runs posthog-cli sourcemap inject + ... upload --directory public/ after the production build, then excludes *.map from the aws s3 sync so source maps stay off Tigris. PostHog resolves stacks back to .ts server-side via the uploaded maps.

Implements part of ClickUp task 86c8x4a3p "Add PostHog error tracking to all UI apps" (1 of 5 frontends — see also council-console, network-dashboard, moonlight-pay, browser-wallet).

Test plan

  • deno task check clean
  • deno task lint clean
  • deno task fmt:check clean
  • deno task test — 7 passed
  • deno task build -- --production emits public/app.js (1.1 MB) + public/app.js.map (3.6 MB)
  • posthog-cli sourcemap inject + upload --directory public/ succeeded locally; PostHog release provider-console@3920118a38a3d40271f755bead546af013fbadbd created
  • Smoke-tested locally: ENVIRONMENT=production deno task serve on :3000 with a real project token in public/config.js, errors land in PostHog Errors dashboard with .ts-resolved stack frames
  • After merge: confirm the testnet/mainnet deploy actions complete the Upload source maps to PostHog step successfully

Caveats

  • Init config uses capture_exceptions: true (posthog-js v1.376+ renamed it from autocapture_exceptions). PostHog's older docs still reference the old name; capture_exceptions is the field actually read by the SDK.
  • iac was updated separately to fan POSTHOG_CLI_API_KEY (personal API key with error_tracking:write + organization:read scopes) to all 5 frontend repos as a GH secret.

AquiGorka added 2 commits May 28, 2026 14:10
…on, source-map upload

- `analytics.ts`: extend init with `capture_exceptions: true`; add a
  `captureException(error, properties?)` export that no-ops in the dev
  NOOP path and forwards to `posthog.captureException` once the array.js
  shim loads. Existing analytics-event capture is untouched.
- `build.ts`: flip `sourcemap` always-on so production bundles emit
  `app.js.map` next to the JS. Maps are NOT shipped publicly — the
  static server already returns 404 for `.map` requests, and the
  deploy step now excludes them from the s3 sync.
- `deploy.yml` (testnet + mainnet): after the production build, run
  `npx --yes @posthog/cli sourcemap inject --directory public/` to
  embed chunk IDs into both `app.js` and `app.js.map`, then upload the
  maps with `... sourcemap upload --directory public/`. Adds the
  `--exclude "*.map"` flag to the existing `aws s3 sync` so source maps
  stay off Tigris. PostHog CLI env: `POSTHOG_CLI_API_KEY` from secrets,
  `POSTHOG_CLI_PROJECT_ID=345524`, `POSTHOG_CLI_HOST=https://us.posthog.com`.

Init config uses `capture_exceptions: true` (posthog-js v1.376+ renamed
from `autocapture_exceptions`). Verified locally with a production
build + posthog-cli upload against the real personal API key.
@AquiGorka AquiGorka merged commit 4805762 into main May 28, 2026
6 checks passed
@AquiGorka AquiGorka deleted the posthog-error-tracking branch May 28, 2026 18:02
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