Skip to content

Conversation

@arabold
Copy link
Owner

@arabold arabold commented Jan 14, 2026

Summary

Fixes #306 - Users could not disable telemetry despite setting DOCS_MCP_TELEMETRY=false.

Root Causes (Two Bugs)

1. Telemetry Proxy Caching Stale State

The telemetry proxy was caching the instance state on first access using Object.assign(). If code accessed the proxy before initTelemetry({ enabled: false }) was called, it would cache a stale enabled state that was never refreshed.

Fix: Changed the proxy to always delegate to the current telemetryInstance instead of caching.

2. Boolean Environment Variable Parsing

z.coerce.boolean() uses JavaScript's Boolean() which treats all non-empty strings as truthy. This meant DOCS_MCP_TELEMETRY=false was being parsed as true.

Fix: Created a custom envBoolean zod schema that properly parses string representations like "false", "0", "no", "off" as false.

Changes

  • src/telemetry/telemetry.ts - Fix proxy to always delegate to current instance
  • src/telemetry/telemetry.test.ts - Add unit tests for proxy behavior
  • src/utils/config.ts - Add envBoolean schema for proper boolean parsing
  • test/telemetry-e2e.test.ts - Add 4 e2e tests verifying telemetry config via log parsing

Testing

  • All telemetry unit tests pass (14 tests)
  • All config unit tests pass (6 tests)
  • All telemetry e2e tests pass (4 tests)
  • Lint, typecheck, and build all pass

E2E Test Coverage

The new e2e tests verify telemetry configuration by parsing debug logs:

  1. DOCS_MCP_TELEMETRY=false → logs "Telemetry disabled (user preference)"
  2. DOCS_MCP_TELEMETRY=true (no API key) → logs "Telemetry disabled (no API key configured)"
  3. --no-telemetry CLI flag → logs "Telemetry disabled (user preference)"
  4. --telemetry=false CLI flag → logs "Telemetry disabled (user preference)"

The telemetry proxy was caching a stale enabled state on first access,
causing DOCS_MCP_TELEMETRY=false to be ignored if any code accessed the
telemetry proxy before initTelemetry() was called.

The fix changes the proxy to always delegate to the current telemetry
instance instead of caching, ensuring configuration changes are always
reflected.

Closes #306
z.coerce.boolean() treats all non-empty strings as true, so
DOCS_MCP_TELEMETRY=false was being parsed as true. Added a custom
envBoolean schema that correctly parses string representations
like 'false', '0', 'no', 'off' as false.

Also added e2e tests to verify telemetry configuration works
correctly via both environment variables and CLI flags.
@arabold arabold merged commit e73d9c4 into main Jan 15, 2026
3 checks passed
@arabold arabold deleted the fix/306-telemetry-disable branch January 15, 2026 02:10
@github-actions
Copy link

🎉 This PR is included in version 1.36.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disabling telemetry doesn't seems to disable telemetry

2 participants