feat(error-tracking): PostHog autocapture + sourcemap upload#35
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
captureExceptioninto the existingsrc/lib/analytics.ts(analytics-event capture is untouched).sourcemap: !isProduction→sourcemap: truesoapp.js.mapis emitted next to the bundle.deploy.yml(testnet + mainnet) runsposthog-cli sourcemap inject+... upload --directory public/after the production build, then excludes*.mapfrom theaws s3 syncso source maps stay off Tigris. PostHog resolves stacks back to.tsserver-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 checkcleandeno task lintcleandeno task fmt:checkcleandeno task test— 7 passeddeno task build -- --productionemitspublic/app.js(1.1 MB) +public/app.js.map(3.6 MB)posthog-cli sourcemap inject + upload --directory public/succeeded locally; PostHog releaseprovider-console@3920118a38a3d40271f755bead546af013fbadbdcreatedENVIRONMENT=production deno task serveon :3000 with a real project token inpublic/config.js, errors land in PostHog Errors dashboard with.ts-resolved stack framesUpload source maps to PostHogstep successfullyCaveats
capture_exceptions: true(posthog-js v1.376+ renamed it fromautocapture_exceptions). PostHog's older docs still reference the old name;capture_exceptionsis the field actually read by the SDK.POSTHOG_CLI_API_KEY(personal API key witherror_tracking:write+organization:readscopes) to all 5 frontend repos as a GH secret.