Skip to content

fix(config): adapt posthog disabled if no keys - #736

Merged
steebchen merged 1 commit into
mainfrom
steebchen-patch-1
Sep 3, 2025
Merged

steebchen merged 1 commit into
mainfrom
steebchen-patch-1

Conversation

@steebchen

@steebchen steebchen commented Sep 3, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Prevents runtime issues by automatically disabling analytics when required environment variables are missing.
  • Chores
    • Adjusts default analytics host handling to a safe fallback.
    • Adds a safeguard to conditionally disable analytics based on environment configuration.

@coderabbitai

coderabbitai Bot commented Sep 3, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Updated 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

Cohort / File(s) Summary
PostHog client config
apps/api/src/posthog.ts
Change default host to process.env.POSTHOG_HOST

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch steebchen-patch-1

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions Bot changed the title Update PostHog host default value and add disabled option feat(config): update host default Sep 3, 2025
@steebchen steebchen changed the title feat(config): update host default fix(config): update host default Sep 3, 2025
@steebchen steebchen changed the title fix(config): update host default fix(config): update posthog host default Sep 3, 2025
@steebchen steebchen changed the title fix(config): update posthog host default fix(config): adapt posthog disabled if no keys Sep 3, 2025
@steebchen
steebchen added this pull request to the merge queue Sep 3, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SDK disabled flag 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 disabled will take effect.
  • Optional: add explicit POSTHOG_DISABLED override 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 6248b41 and 37b7114.

📒 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 use db().query.<table>.findMany() or db().query.<table>.findFirst()

Files:

  • apps/api/src/posthog.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never use as any or : any in TypeScript files.

Files:

  • apps/api/src/posthog.ts
apps/{api,gateway}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/{api,gateway}/**/*.{ts,tsx}: Use Drizzle with the latest object syntax for database operations
For read queries, use db().query.

.findMany() or 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 APIs

Files:

  • apps/api/src/posthog.ts
apps/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

Merged via the queue into main with commit 1f4c469 Sep 3, 2025
14 checks passed
@steebchen
steebchen deleted the steebchen-patch-1 branch September 3, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant