Skip to content

feat (desktop): disable telemetry option in settings#1048

Merged
AviPeltz merged 1 commit into
mainfrom
AviPeltz/disable-telemetry
Feb 3, 2026
Merged

feat (desktop): disable telemetry option in settings#1048
AviPeltz merged 1 commit into
mainfrom
AviPeltz/disable-telemetry

Conversation

@AviPeltz
Copy link
Copy Markdown
Collaborator

@AviPeltz AviPeltz commented Jan 29, 2026

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

Summary by CodeRabbit

New Features

  • Added telemetry preferences to settings, allowing users to control anonymous usage data collection.
  • New "Send anonymous usage data" toggle in Behavior settings.
  • Telemetry state automatically synchronizes with analytics services based on user preference.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

The PR adds telemetry toggle functionality to the desktop application. It introduces a new telemetryEnabled database setting with TRPC procedures for querying and updating, a React component that synchronizes the setting with PostHog, and UI controls in settings for users to toggle telemetry opt-in/out. The analytics module gates tracking operations when telemetry is disabled.

Changes

Cohort / File(s) Summary
Database Schema
packages/local-db/drizzle/0016_add_telemetry_enabled.sql, packages/local-db/drizzle/meta/..., packages/local-db/src/schema/schema.ts
Adds telemetry_enabled integer column to settings table and updates schema snapshot/journal entries.
Shared Constants
apps/desktop/src/shared/constants.ts
Adds DEFAULT_TELEMETRY_ENABLED = true constant.
Settings TRPC Router
apps/desktop/src/lib/trpc/routers/settings/index.ts
Introduces getTelemetryEnabled query and setTelemetryEnabled mutation procedures with database upsert semantics.
Analytics Module
apps/desktop/src/main/lib/analytics/index.ts
Adds isTelemetryEnabled() guard to read telemetry state from DB; gates track() invocations when telemetry is disabled.
Settings Search & Visibility
apps/desktop/src/renderer/routes/_authenticated/settings/utils/settings-search/settings-search.ts
Registers new BEHAVIOR_TELEMETRY setting item with section, title, description, and keywords for search and visibility logic.
Telemetry Sync Component
apps/desktop/src/renderer/components/TelemetrySync/*
Creates React component that observes telemetryEnabled state and toggles PostHog opt-in/out capturing; exports via barrel index.
Behavior Settings UI
apps/desktop/src/renderer/routes/_authenticated/settings/behavior/components/BehaviorSettings/BehaviorSettings.tsx
Integrates telemetry toggle into settings form with query/mutation hooks, optimistic updates, error handling, and conditional rendering of telemetry switch.
Root Layout
apps/desktop/src/renderer/routes/layout.tsx
Adds <TelemetrySync /> component to RootLayout to enable telemetry state synchronization.

Sequence Diagram

sequenceDiagram
    actor User
    participant UI as BehaviorSettings UI
    participant TRPC as TRPC Router
    participant DB as Database
    participant Sync as TelemetrySync
    participant PostHog as PostHog
    participant Analytics as Analytics Module

    User->>UI: Toggle telemetry switch
    UI->>UI: Optimistic update
    UI->>TRPC: setTelemetryEnabled({ enabled })
    TRPC->>DB: Upsert settings.telemetry_enabled
    DB-->>TRPC: Success
    TRPC-->>UI: { success: true }
    
    UI->>TRPC: Invalidate getTelemetryEnabled
    TRPC->>DB: Query telemetry_enabled
    DB-->>TRPC: Value
    TRPC-->>Sync: Updated state
    
    Sync->>Sync: Effect triggered
    alt enabled === true
        Sync->>PostHog: posthog.opt_in_capturing()
    else enabled === false
        Sync->>PostHog: posthog.opt_out_capturing()
    end
    PostHog-->>Sync: Updated
    
    Analytics->>DB: Check isTelemetryEnabled()
    DB-->>Analytics: telemetry_enabled value
    alt Telemetry disabled
        Analytics->>Analytics: Skip track() execution
    else Telemetry enabled
        Analytics->>PostHog: Send event
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • Kitenite

🐰 A telemetry toggle hops into place,
PostHog and DB join the race,
Settings sync with graceful ease,
Analytics flows as users please,
Privacy choice, now user-led! 📊✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description largely follows the template with Type of Change marked as 'New feature', but critical sections (Description, Related Issues, Testing, Screenshots, Additional Notes) are empty or incomplete. Fill in the Description section with details about the telemetry feature. Complete Testing section with verification steps. Add Related Issues if applicable. These details would strengthen reviewer understanding.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a telemetry toggle feature to the settings UI, which is the primary user-facing functionality across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch AviPeltz/disable-telemetry

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 29, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ⚠️ Neon database branch
  • ⚠️ Electric Fly.io app

Thank you for your contribution! 🎉

@AviPeltz AviPeltz marked this pull request as ready for review February 2, 2026 06:51
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apps/desktop/src/main/lib/analytics/index.ts`:
- Around line 26-33: The catch in isTelemetryEnabled silently swallows errors;
update the catch block to log the caught error with context using the prefixed
pattern (e.g. "[analytics/isTelemetryEnabled]") before returning
DEFAULT_TELEMETRY_ENABLED—capture the exception from the failing call to
localDb.select().from(settings).get() and call console.error (or the module's
logger) with a clear message and the error object to ensure errors are surfaced
for debugging.
🧹 Nitpick comments (1)
apps/desktop/src/lib/trpc/routers/settings/index.ts (1)

410-428: Extract the settings row id to a named constant.
id: 1 is a magic number; consider a module‑level SETTINGS_ROW_ID for clarity and consistency.

♻️ Suggested refactor
+const SETTINGS_ROW_ID = 1;
-					.values({ id: 1, telemetryEnabled: input.enabled })
+					.values({ id: SETTINGS_ROW_ID, telemetryEnabled: input.enabled })
Based on learnings: Avoid magic numbers by extracting them to named constants at module top.

Comment on lines +26 to +33
function isTelemetryEnabled(): boolean {
try {
const row = localDb.select().from(settings).get();
return row?.telemetryEnabled ?? DEFAULT_TELEMETRY_ENABLED;
} catch {
return DEFAULT_TELEMETRY_ENABLED;
}
}
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.

⚠️ Potential issue | 🟡 Minor

Add error logging in the catch block.

The catch block silently swallows errors without any logging. Per coding guidelines, errors should at minimum be logged with context to aid debugging.

🛡️ Proposed fix to add error logging
 function isTelemetryEnabled(): boolean {
 	try {
 		const row = localDb.select().from(settings).get();
 		return row?.telemetryEnabled ?? DEFAULT_TELEMETRY_ENABLED;
-	} catch {
+	} catch (error) {
+		console.error("[analytics/telemetry] Failed to read telemetry setting:", error);
 		return DEFAULT_TELEMETRY_ENABLED;
 	}
 }

As per coding guidelines: "Never swallow errors silently; at minimum log them with context" and "Use prefixed console logging with pattern [domain/operation] message for all logging".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function isTelemetryEnabled(): boolean {
try {
const row = localDb.select().from(settings).get();
return row?.telemetryEnabled ?? DEFAULT_TELEMETRY_ENABLED;
} catch {
return DEFAULT_TELEMETRY_ENABLED;
}
}
function isTelemetryEnabled(): boolean {
try {
const row = localDb.select().from(settings).get();
return row?.telemetryEnabled ?? DEFAULT_TELEMETRY_ENABLED;
} catch (error) {
console.error("[analytics/telemetry] Failed to read telemetry setting:", error);
return DEFAULT_TELEMETRY_ENABLED;
}
}
🤖 Prompt for AI Agents
In `@apps/desktop/src/main/lib/analytics/index.ts` around lines 26 - 33, The catch
in isTelemetryEnabled silently swallows errors; update the catch block to log
the caught error with context using the prefixed pattern (e.g.
"[analytics/isTelemetryEnabled]") before returning
DEFAULT_TELEMETRY_ENABLED—capture the exception from the failing call to
localDb.select().from(settings).get() and call console.error (or the module's
logger) with a clear message and the error object to ensure errors are surfaced
for debugging.

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