payload-posthog

Error Tracking

Reports Payload's global afterError hook to PostHog.

payloadPosthog({
  apiKey: process.env.POSTHOG_API_KEY!,
  errorTracking: {
    minStatusCode: 500, // default — only server errors, not validation/4xx
    properties: ({ error, req }) => ({ path: req?.pathname }),
  },
})

This wires into config.hooks.afterError — Payload's global error hook, which fires for REST, GraphQL, and non-collection endpoint errors alike — and calls captureException(). Existing afterError hooks are preserved, not replaced.

By default only errors at or above 500 are reported, so routine validation failures (400s) don't clutter PostHog's error tracking. Raise or lower minStatusCode to change that cutoff.