SurfSense/surfsense_web/lib/posthog/server.ts
DESKTOP-RTLN3BA\$punk 1ab395a34e feat: enhance error handling with PostHog integration
- Added PostHog error capturing for non-authentication errors in BaseApiService.
- Refactored PostHog client initialization to ensure a single instance is used across the application.
2026-03-12 01:28:39 -07:00

19 lines
450 B
TypeScript

import { PostHog } from "posthog-node";
let posthogInstance: PostHog | null = null;
export default function PostHogClient() {
if (!process.env.NEXT_PUBLIC_POSTHOG_KEY) {
throw new Error("NEXT_PUBLIC_POSTHOG_KEY is not set");
}
if (!posthogInstance) {
posthogInstance = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
host: process.env.NEXT_PUBLIC_POSTHOG_HOST,
flushAt: 1,
flushInterval: 0,
});
}
return posthogInstance;
}