-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from mendableai/feat/posthog-logging
Add Posthog Logging
- Loading branch information
Showing
9 changed files
with
99 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { PostHog } from 'posthog-node'; | ||
import "dotenv/config"; | ||
|
||
export default function PostHogClient() { | ||
const posthogClient = new PostHog(process.env.POSTHOG_API_KEY, { | ||
host: process.env.POSTHOG_HOST, | ||
flushAt: 1, | ||
flushInterval: 0 | ||
}); | ||
return posthogClient; | ||
} | ||
|
||
class MockPostHog { | ||
capture() {} | ||
} | ||
|
||
// Using the actual PostHog class if POSTHOG_API_KEY exists, otherwise using the mock class | ||
// Additionally, print a warning to the terminal if POSTHOG_API_KEY is not provided | ||
export const posthog = process.env.POSTHOG_API_KEY | ||
? PostHogClient() | ||
: (() => { | ||
console.warn( | ||
"POSTHOG_API_KEY is not provided - your events will not be logged. Using MockPostHog as a fallback. See posthog.ts for more." | ||
); | ||
return new MockPostHog(); | ||
})(); |