Skip to content

Add PostHog client-side error tracking and session replay#258

Merged
jakebromberg merged 1 commit intomainfrom
feat/posthog-error-tracking
Apr 21, 2026
Merged

Add PostHog client-side error tracking and session replay#258
jakebromberg merged 1 commit intomainfrom
feat/posthog-error-tracking

Conversation

@jakebromberg
Copy link
Copy Markdown
Member

@jakebromberg jakebromberg commented Feb 26, 2026

Summary

  • Replace reverted Sentry with PostHog client-side error tracking (capture_exceptions, session replay, pageview tracking)
  • Integrate posthog.captureException() into RTK Query error middleware with endpoint name/status metadata
  • Add X-Request-Id header to all backend API requests for cross-service correlation

Closes #257

Test plan

  • npm run build succeeds
  • lib/__tests__/posthog.test.ts -- 5 tests pass (init config, default host, no-op without key, no-op on server, skip re-init)
  • No regressions in existing test suite
  • Deploy to Cloudflare Pages preview, verify PostHog /e batch requests fire
  • Trigger JS error in console, confirm $exception in PostHog Error Tracking
  • Trigger API error, confirm RTK Query error appears in PostHog with endpoint name
  • Verify API requests include X-Request-Id header in devtools
  • Set NEXT_PUBLIC_POSTHOG_KEY and NEXT_PUBLIC_POSTHOG_HOST in Cloudflare Pages secrets

Note: E2E tests depend on #271 and WXYC/Backend-Service#223. E2E will pass once those merge.

@jakebromberg jakebromberg force-pushed the feat/posthog-error-tracking branch from 23f9ece to 57297c8 Compare March 2, 2026 16:36
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 2, 2026

Deploying wxyc-dj with  Cloudflare Pages  Cloudflare Pages

Latest commit: e5ecc5d
Status:🚫  Build failed.

View logs

Replace the reverted Sentry integration with PostHog for client-side
error tracking, automatic exception capture, session replay, and
pageview tracking. Add X-Request-Id header to API requests for
cross-service correlation with Backend-Service Sentry traces.

- posthog-js with capture_exceptions for window.onerror/unhandledrejection
- PostHogProvider wrapping the component tree with pageview tracking
- global-error.tsx error boundary capturing render errors to PostHog
- RTK Query error middleware reporting API failures to PostHog
- X-Request-Id (crypto.randomUUID) on every backend API request
- productionBrowserSourceMaps for stack trace resolution
@jakebromberg jakebromberg force-pushed the feat/posthog-error-tracking branch from c22a56f to e5ecc5d Compare April 21, 2026 17:37
@jakebromberg jakebromberg merged commit b5fbc82 into main Apr 21, 2026
0 of 3 checks passed
@jakebromberg jakebromberg deleted the feat/posthog-error-tracking branch April 21, 2026 17:59
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.

Add PostHog client-side error tracking and session replay

2 participants