Skip to content

fix(error-tracking): init the Next.js browser SDK at the top level of instrumentation-client.ts - #443

Merged
ablaszkiewicz merged 1 commit into
mainfrom
fix/nextjs-error-tracking-coverage
Oct 28, 2026
Merged

ablaszkiewicz merged 1 commit into
mainfrom
fix/nextjs-error-tracking-coverage

Conversation

@ablaszkiewicz

@ablaszkiewicz ablaszkiewicz commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

wizard error-tracking on a Next.js app with no PostHog put posthog.init inside an exported register() in instrumentation-client.ts. Next.js never calls that export, so the browser SDK never started and no browser error reached PostHog. The build passed, so the verify task didn't catch it.

Changes

A Next.js rule in context/commandments.yaml: call posthog.init at the top level of instrumentation-client.ts, with the missing-configuration guard as a top-level if/else around it.

Test plan

  • npm test (220 passing)
  • wizard error-tracking with this branch (--local-context-mill) on four workbench Next.js apps without PostHog. Every run completed, and each put posthog.init at the top level:
    • error-tracking/no-posthog-next (Next.js 16, App Router)
    • the same app moved to src/app
    • basic-integration/next-js/15-app-router-saas (Next.js 15, App Router)
    • basic-integration/next-js/15-pages-router-saas (Next.js 15, Pages Router)
  • Each app built and started with next start, then loaded in headless Chrome, where a browser error tagged with a marker was thrown. The browser SDK sent requests and the marked $exception reached PostHog in all four.
  • Control: the same check with the init wrapped in export function register() sends no request to PostHog and no exception arrives.

The two SaaS apps need their own database and Stripe settings to build, so they built with placeholder values, and 15-app-router-saas renders /pricing per request instead of prerendering it with a call to Stripe.

🤖 Generated with Claude Code

@github-actions

Copy link
Copy Markdown

🧙 Wizard CI

Run the Wizard CI and test your changes against wizard-workbench example apps by replying with a GitHub comment using one of the following commands:

Test all apps:

  • /wizard-ci all

Test all apps in a directory:

  • /wizard-ci ai-observability
  • /wizard-ci basic-integration
  • /wizard-ci feature-flags
  • /wizard-ci mcp-analytics
  • /wizard-ci replay-vision
  • /wizard-ci revenue
  • /wizard-ci self-driving
  • /wizard-ci warehouse
  • /wizard-ci warehouse-seeded

Test an individual app:

  • /wizard-ci ai-observability/anthropic
  • /wizard-ci ai-observability/google-adk
  • /wizard-ci ai-observability/groq
Show more apps
  • /wizard-ci ai-observability/manual-capture
  • /wizard-ci ai-observability/openai
  • /wizard-ci ai-observability/openai-agents
  • /wizard-ci ai-observability/opentelemetry
  • /wizard-ci ai-observability/vercel-ai
  • /wizard-ci basic-integration/android
  • /wizard-ci basic-integration/angular
  • /wizard-ci basic-integration/astro
  • /wizard-ci basic-integration/django
  • /wizard-ci basic-integration/fastapi
  • /wizard-ci basic-integration/flask
  • /wizard-ci basic-integration/flutter
  • /wizard-ci basic-integration/javascript-node
  • /wizard-ci basic-integration/javascript-web
  • /wizard-ci basic-integration/laravel
  • /wizard-ci basic-integration/next-js
  • /wizard-ci basic-integration/nuxt
  • /wizard-ci basic-integration/python
  • /wizard-ci basic-integration/rails
  • /wizard-ci basic-integration/react-native
  • /wizard-ci basic-integration/react-router
  • /wizard-ci basic-integration/sveltekit
  • /wizard-ci basic-integration/swift
  • /wizard-ci basic-integration/tanstack-router
  • /wizard-ci basic-integration/tanstack-start
  • /wizard-ci basic-integration/vue
  • /wizard-ci feature-flags/django
  • /wizard-ci feature-flags/next-js
  • /wizard-ci mcp-analytics/custom-dispatcher
  • /wizard-ci mcp-analytics/typescript-sdk
  • /wizard-ci replay-vision/javascript-node
  • /wizard-ci replay-vision/next-js
  • /wizard-ci replay-vision/react-vite
  • /wizard-ci revenue/stripe
  • /wizard-ci self-driving/astro
  • /wizard-ci self-driving/fastapi
  • /wizard-ci self-driving/nuxt
  • /wizard-ci self-driving/react-router
  • /wizard-ci self-driving/sveltekit
  • /wizard-ci warehouse/monorepo-env
  • /wizard-ci warehouse/multi-source-next
  • /wizard-ci warehouse/stripe-node
  • /wizard-ci warehouse/zero-source
  • /wizard-ci warehouse-seeded/next-stripe
  • /wizard-ci warehouse-seeded/next-stripe-declined

Test against a wizard branch:

  • /wizard-ci all wizard:my-branch

Add wizard:<branch> to any command above to pin the wizard branch. It defaults to main.

Results will be posted here when complete.

Comment thread example-apps/next-pages-router/src/instrumentation.ts Outdated
Comment thread example-apps/next-pages-router/src/instrumentation.ts Outdated
@ablaszkiewicz

Copy link
Copy Markdown
Contributor Author

@hpouillot this was AI generated and I haven't yet manually checked the code. I didn't realize agent created this PR in a "ready" state

@ablaszkiewicz
ablaszkiewicz force-pushed the fix/nextjs-error-tracking-coverage branch from ae7f5a8 to d10bcfa Compare October 28, 2026 10:08
@ablaszkiewicz
ablaszkiewicz marked this pull request as draft October 28, 2026 10:20
@ablaszkiewicz
ablaszkiewicz force-pushed the fix/nextjs-error-tracking-coverage branch from d10bcfa to cf761bd Compare October 28, 2026 10:26
@ablaszkiewicz ablaszkiewicz changed the title fix(error-tracking): init the Next.js browser SDK at top level and capture errors in every runtime fix(error-tracking): init the Next.js browser SDK at the top level of instrumentation-client.ts Oct 28, 2026
@ablaszkiewicz
ablaszkiewicz marked this pull request as ready for review October 28, 2026 10:28
… instrumentation-client.ts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ablaszkiewicz
ablaszkiewicz force-pushed the fix/nextjs-error-tracking-coverage branch from cf761bd to 92f8b6a Compare October 28, 2026 11:25
@ablaszkiewicz
ablaszkiewicz merged commit 148f9b8 into main Oct 28, 2026
16 checks passed
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.

2 participants