Skip to content

feat(observability): configure PostHog error tracking#385

Open
huv1k wants to merge 1 commit into
mainfrom
configure-posthogs-error-tracking-eng-4261
Open

feat(observability): configure PostHog error tracking#385
huv1k wants to merge 1 commit into
mainfrom
configure-posthogs-error-tracking-eng-4261

Conversation

@huv1k

@huv1k huv1k commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Enables PostHog error tracking for the dashboard. Turns on capture_exceptions (unhandled errors + rejections) and tags every event with an environment super-property (from NEXT_PUBLIC_VERCEL_ENV) so prod/preview/dev are distinguishable. Currently will be running only in prod.

Reports React render errors via posthog.captureException in the shared ErrorBoundary and wraps the dashboard layout in a PostHogErrorBoundary. Uploads source maps during the build via @posthog/nextjs-config (gated on POSTHOG_API_KEY, deleteAfterUpload, release = commit SHA), with the new build-time env vars documented in env.ts/.env.example.

@linear-code

linear-code Bot commented Jun 10, 2026

Copy link
Copy Markdown

ENG-4261

@cla-bot cla-bot Bot added the cla-signed label Jun 10, 2026
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Jun 12, 2026 2:21pm

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 405e4554ed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread next.config.ts
Comment thread src/ui/error.tsx
Comment on lines +36 to +37
if (process.env.NEXT_PUBLIC_POSTHOG_KEY) {
posthog.captureException(error)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Initialize PostHog before global error capture

When this shared ErrorBoundary is rendered from app/global-error.tsx, it is outside RootLayout/ClientProviders, so PostHogProvider never runs posthog.init; checking only NEXT_PUBLIC_POSTHOG_KEY here calls captureException on an uninitialized singleton and drops root-layout/provider failures. Use a path that initializes a client for the global fallback, or guard on a loaded client and handle global errors separately.

Useful? React with 👍 / 👎.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Comment thread src/ui/error.tsx
@drankou drankou changed the title feat(observability): configure PostHog error tracking (ENG-4261) feat(observability): configure PostHog error tracking Jun 12, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Comment thread src/features/posthog-sanitize.ts Outdated
- Enable capture_exceptions (unhandled errors + rejections) in the PostHog
  provider and tag every event with an `environment` super-property derived
  from NEXT_PUBLIC_VERCEL_ENV (prod/preview/dev).
- Report React render errors via posthog.captureException in the shared
  ErrorBoundary, and wrap the dashboard layout in a PostHogErrorBoundary.
- Upload source maps during the build via @posthog/nextjs-config
  (deleteAfterUpload), gated on POSTHOG_API_KEY, release = commit SHA.
- Add POSTHOG_API_KEY / POSTHOG_PROJECT_ID / NEXT_PUBLIC_VERCEL_ENV to the
  env schema and .env.example.
- Mask the raw error message in the shared ErrorBoundary and vertically
  center the dashboard route error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant