mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 08:46:22 +02:00
- Added PostHog error capturing for non-authentication errors in BaseApiService. - Refactored PostHog client initialization to ensure a single instance is used across the application.
19 lines
450 B
TypeScript
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;
|
|
}
|