fix: skip PostHog/Gleap init when key is an .env.example placeholder#3108
fix: skip PostHog/Gleap init when key is an .env.example placeholder#3108Abdul-Moiz31 wants to merge 1 commit into
Conversation
|
@Abdul-Moiz31 is attempting to deploy a commit to the Onlook Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
Caution Review failedAn error occurred during the review process. Please try again later. 📝 WalkthroughWalkthroughTelemetry SDKs PostHog and Gleap now reject placeholder and unconfigured API keys across client-side and server-side modules. An ChangesPlatform Telemetry Configuration Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: private package registry requires authentication. Disable ESLint in CodeRabbit settings or use public packages. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
3dc17ac to
6b222dc
Compare
Description
PostHog (and Gleap) initialize whenever their env key is truthy, which accepts the placeholder string shipped in
.env.example:NEXT_PUBLIC_POSTHOG_KEY="<Your PostHog API key from [https://posthog.com/docs/libraries/next-js>](https://posthog.com/docs/libraries/next-js%3E)"For any new contributor who copies
.env.exampleto.envwithout filling these out, every page load floods the console with PostHog 401s and 404s. These errors hide real ones during local development.Reject empty values and any value starting with
<before initializing. Same shape of placeholder appears forNEXT_PUBLIC_GLEAP_API_KEYandNEXT_PUBLIC_POSTHOG_HOST, so the same guard is applied to Gleap.Related Issues
closes #2707
This fix was previously attempted in #2739 (closed, unmerged). During the subsequent refactor that consolidated PostHog and Gleap initialization into the new
TelemetryProvider, the guard was lost — the current check attelemetry-provider.tsx:25only validates truthiness.Type of Change
Testing
Reproduced and verified locally on
main:Repro (current behaviour without fix):
apps/web/client/.env.examplePostHog lines intoapps/web/client/.envverbatim.bun dev, openhttp://localhost:3000, open DevTools Console.GET https://us-assets.i.posthog.com/array/%3CYour%20PostHog%20API%20key...%3E/config.js 404 (Not Found)POST https://us.i.posthog.com/flags/?... 401 (Unauthorized)POST https://us.i.posthog.com/e/?... 401 (Unauthorized)With this fix:
.env→ no PostHog network calls, no console errors.bun run setup:envoutput) → no errors, no warnings, unchanged behaviour.bun typecheckpasses.bun testpasses (1045/1045).Files Changed
apps/web/client/src/components/telemetry-provider.tsx— client-side PostHog + Gleap init guards (3 callsites)apps/web/client/src/utils/analytics/server.ts— server-side PostHog singletonAlso removed two
console.warncalls that fired noisily on every page load when keys were intentionally unset. The unconfigured state is now silent, matching how every other optional integration in the file behaves.Additional Notes
The guard is intentionally narrow —
!value.startsWith("<")— to avoid rejecting valid keys. The current.env.exampleplaceholders all follow the<...>shape; if future placeholders use a different shape, the check should be extended accordingly.Summary by CodeRabbit
Bug Fixes
Chores