fix(config): adapt posthog disabled if no keys - #736
Conversation
WalkthroughUpdated PostHog client initialization in apps/api/src/posthog.ts to change the default host to "none" and add a disabled flag that turns off PostHog when POSTHOG_KEY or POSTHOG_HOST are missing. Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant Env as Env Vars
participant PH as PostHog Client
App->>Env: Read POSTHOG_KEY, POSTHOG_HOST
Env-->>App: Values or missing
App->>PH: Initialize PostHog({ host: POSTHOG_HOST || "none", disabled: !KEY || !HOST })
alt disabled = true
Note over PH: Client operations are no-ops
else disabled = false
Note over PH: Client active with provided host
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
apps/api/src/posthog.ts (2)
4-4: Avoid sentinel "none" for host; omit the field when undefined.Passing a non-URL like "none" could break if the SDK validates/parses host in future. Prefer conditionally including host only when set.
export const posthog = new PostHog(process.env.POSTHOG_KEY || "key", { - host: process.env.POSTHOG_HOST || "none", - disabled: !process.env.POSTHOG_KEY || !process.env.POSTHOG_HOST, + ...(process.env.POSTHOG_HOST ? { host: process.env.POSTHOG_HOST } : {}), + disabled: !process.env.POSTHOG_KEY || !process.env.POSTHOG_HOST, });
5-5: Confirm PostHog SDKdisabledflag is supported (posthog-node v4.18.0)
- Verified in apps/api/package.json and apps/ui/package.json: posthog-node 4.18.0 (≥ 4.0.0), so
disabledwill take effect.- Optional: add explicit
POSTHOG_DISABLEDoverride in apps/api/src/posthog.ts:- disabled: !process.env.POSTHOG_KEY || !process.env.POSTHOG_HOST, + disabled: + process.env.POSTHOG_DISABLED?.toLowerCase() === "true" || + !process.env.POSTHOG_KEY || + !process.env.POSTHOG_HOST,
- Optional: shorten request timeout to fail fast on misconfigured host:
new PostHog(process.env.POSTHOG_KEY || "key", { + requestTimeout: 3000, })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
apps/api/src/posthog.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
Use localStorage instead of cookies for client-side data persistence
Files:
apps/api/src/posthog.ts
**/*.{js,ts}
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.{js,ts}: Use drizzle with the latest object syntax for database operations
For read queries, always usedb().query.<table>.findMany()ordb().query.<table>.findFirst()
Files:
apps/api/src/posthog.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
Never use
as anyor: anyin TypeScript files.
Files:
apps/api/src/posthog.ts
apps/{api,gateway}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
.findMany() or db().query.
apps/{api,gateway}/**/*.{ts,tsx}: Use Drizzle with the latest object syntax for database operations
For read queries, use db().query..findFirst()
apps/{api,gateway}/**/*.{ts,tsx}: Use the Hono framework for backend HTTP services in apps/api and apps/gateway
Use Zod for request/response validation in backend routes and handlers
Maintain OpenAPI/Swagger documentation for backend APIsFiles:
apps/api/src/posthog.tsapps/api/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
In apps/api (Hono), always use Hono + Zod + OpenAPI for validation and typesafety
Files:
apps/api/src/posthog.ts
Summary by CodeRabbit