thunderbolt icon indicating copy to clipboard operation
thunderbolt copied to clipboard

fix(#701): disable telemetry by default for self-hosted (OIDC) instances

Open rbalogic opened this issue 7 months ago • 3 comments

This PR updates the default settings for data collection to be opt-in rather than opt-out for self-hosted/enterprise environments.

Changes:

  • Centralized Logic: Introduced getDefaultDataCollectionValue in src/defaults/settings.ts to manage the default-value logic.
  • Improved Implementation: Refactored to use the existing isOidcMode() utility from @/lib/auth-mode, ensuring consistency and preventing logic drift.
  • Cleaned up Call Sites: Removed manual import.meta.env passing when calling the helper in settings.ts, posthog.tsx, and preferences.tsx.
  • Tests: Added and updated unit tests in src/defaults/settings.test.ts to verify the logic across different modes using mocked module behavior.

Validation:

  • Verified that data_collection defaults to false when isOidcMode() is true.
  • Verified that data_collection defaults to true for consumer mode.
  • All tests passed via bun test.

Closes #701


[!NOTE] Low Risk Low risk: only flips the default data_collection setting to opt-out, primarily affecting analytics initialization and the preferences UI default state.

Overview Telemetry is now disabled by default by changing the default data_collection setting value to false.

This default is applied consistently in both PostHog initialization (initPosthog fallback settings) and the Preferences settings page (useSettings defaults), so new/unspecified installs start with analytics opt-out unless the user enables it.

Reviewed by Cursor Bugbot for commit 40bfcc266a2e4b8579a819f02bdeb0f2e0e11ebf. Bugbot is set up for automated code reviews on this repo. Configure here.

rbalogic avatar Apr 21 '26 21:04 rbalogic

Hey @rbalogic thanks so much for this PR! Really appreciate the contribution.

I'd love to see this get merged if you want to make a few adjustments:

  • We can actually go ahead and disable telemetry by default fully (eg just make it false instead of dependent on OIDC mode). The reasoning here is that OIDC is one auth method, but isn't necessarily what I would use as the determining factor for whether a deployment is self-hosted or not.
  • Since we're defaulting to not enabled, we can simply use the presence of a posthog api key in the backend env vars as the determining factor. If there's no env key provided, we simply don't pass anything to the frontend, and the frontend simply shouldn't enable it.
  • The other thing is that I'd say we can probably remove the tests - or if any tests do make sense, we can find a way to use dependency injection instead of mocking.

cjroth avatar Apr 30 '26 19:04 cjroth

@cjroth Thanks for the feedback! 🙌

I’ve implemented the requested changes:

  • Telemetry is now disabled by default unconditionally (no longer tied to OIDC mode). The frontend default for data_collection is now simply false.
  • Kept the frontend behavior aligned with the existing flow: if the backend does not provide a usable PostHog API key, PostHog won’t initialize on the client.
  • Removed the mock-based tests that covered the OIDC-dependent defaulting logic, since that logic is no longer needed.

Please take another look when you have a moment—happy to iterate further or make any additional tweaks before merge. Thanks again for the guidance!

rbalogic avatar Apr 30 '26 20:04 rbalogic

@cjroth Please review the changes when you can, Thanks.

rbalogic avatar May 06 '26 12:05 rbalogic

Preview environment destroyed 🧹

Stack preview-pr-714 and its Cloudflare subdomain have been cleaned up.

github-actions[bot] avatar May 24 '26 19:05 github-actions[bot]

Hi @cjroth @raivieiraadriano92 @darkbanjo @ital0 Can you please review this PR when you have some time? Thanks.

rbalogic avatar May 24 '26 19:05 rbalogic

Thanks for the contribution @rbalogic!

cjroth avatar May 26 '26 21:05 cjroth