Install
Add the PostHog Node SDK to your app:Prerequisites
You need:- a PostHog project token
- your PostHog host, such as
https://us.i.posthog.com - a Redop server running on Bun
Step 1: Create the client
Create the PostHog client once at module scope.Step 2: Enable exception autocapture
PostHog’s Node.js error tracking docs support exception autocapture for uncaught exceptions and unhandled rejections.Step 3: Capture Redop errors explicitly
Redop gives you a better place to attach request metadata withonError(...). Manual capture is useful when you want tool names, transport, or request IDs included with the exception.
Step 4: Use stable identifiers
PostHog’s Node docs emphasize that backend events need a stabledistinctId. For Redop, avoid random IDs when you want server-side errors to connect to frontend activity or user history.
Good identifiers include:
- authenticated user ID
- tenant ID
- API key owner ID
- an internal actor or account ID
ctx.requestId only for request correlation when you do not have a better user or tenant identity.
Step 5: Flush on shutdown
The Node SDK batches events in the background. Flush before shutdown so pending exceptions are not lost.shutdown() before exit.