Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Next.js error tracking guide: recommend `@posthog/next`'s `onRequestError` instead of a hand-written one

Closed Beginner friendly
#20,867 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Domain
documentation

Research direction

Start with the server-side section of the Next.js error tracking guide at https://posthog.com/docs/error-tracking/installation/nextjs and compare its hand-written instrumentation.ts example with the onRequestError and createOnRequestError exports from @posthog/next. Update the guide to recommend the package API and show the options example if useful; done when the documented setup reflects the built-in integration and its stated benefits.

Written by the indexing model from the issue text.

Description

The server-side section of the Next.js error tracking guide has every app write its own onRequestError in instrumentation.ts: create a posthog-node client, parse the posthog-js cookie by hand to find the person, and call captureException.

@posthog/next already ships this as onRequestError / createOnRequestError, so the guide could be:

// instrumentation.ts
export { onRequestError } from '@posthog/next'

or, with options:

import { createOnRequestError } from '@posthog/next'

export const onRequestError = createOnRequestError({
  serverOptions: { requestTimeout: 3000, fetchRetryCount: 0 },
})

Compared with the guide's snippet, it:

  • reads the cookie for this project's key, not whichever ph_phc_…_posthog cookie the regex matches first
  • adds $session_id and $device_id, so the server exception links to the session replay
  • adds the Next.js request context ($pathname, $http_method, route path and type, error digest)
  • respects the posthog-js opt-out cookie
  • sends immediately and never throws from the hook

We only found @posthog/next by reading the posthog-js source, after hand-rolling the guide's version ourselves.

Dominant language
TypeScript
Stars
1.2k
Forks
932
Avg merge
1d 14h
Merged PRs (30d)
708

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PostHog/posthog.com

All issues in PostHog/posthog.com

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.