fix(telemetry): respect disabled state from initTelemetry #308
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 beforeinitTelemetry({ 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
telemetryInstanceinstead of caching.2. Boolean Environment Variable Parsing
z.coerce.boolean()uses JavaScript'sBoolean()which treats all non-empty strings as truthy. This meantDOCS_MCP_TELEMETRY=falsewas being parsed astrue.Fix: Created a custom
envBooleanzod schema that properly parses string representations like"false","0","no","off"asfalse.Changes
src/telemetry/telemetry.ts- Fix proxy to always delegate to current instancesrc/telemetry/telemetry.test.ts- Add unit tests for proxy behaviorsrc/utils/config.ts- AddenvBooleanschema for proper boolean parsingtest/telemetry-e2e.test.ts- Add 4 e2e tests verifying telemetry config via log parsingTesting
E2E Test Coverage
The new e2e tests verify telemetry configuration by parsing debug logs:
DOCS_MCP_TELEMETRY=false→ logs "Telemetry disabled (user preference)"DOCS_MCP_TELEMETRY=true(no API key) → logs "Telemetry disabled (no API key configured)"--no-telemetryCLI flag → logs "Telemetry disabled (user preference)"--telemetry=falseCLI flag → logs "Telemetry disabled (user preference)"