From b985c1a32d98b8d3343ca5a742d32e76fdad2586 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 28 Nov 2025 18:37:18 +0530 Subject: [PATCH 1/6] fix: use more intuitive envvars to manage OTLP and PostHog telemetry settings Co-Authored-By: Ross Golder --- .../cli/src/telemetry/posthogService.test.ts | 33 +++++++++++++++++++ .../cli/src/telemetry/posthogService.ts | 31 ++++++++++++++--- .../cli/src/telemetry/telemetryService.ts | 13 ++++++-- 3 files changed, 71 insertions(+), 6 deletions(-) diff --git a/extensions/cli/src/telemetry/posthogService.test.ts b/extensions/cli/src/telemetry/posthogService.test.ts index 7fd95204d..6e60de95e 100644 --- a/extensions/cli/src/telemetry/posthogService.test.ts +++ b/extensions/cli/src/telemetry/posthogService.test.ts @@ -152,5 +152,38 @@ describe("PosthogService", () => { expect(client).toBeUndefined(); expect(dns.lookup).toHaveBeenCalledTimes(1); }); + + it("returns false when DNS resolves to 0.0.0.0 (blocked)", async () => { + const dns: any = (await import("dns/promises")).default; + dns.lookup.mockResolvedValueOnce({ + address: "0.0.0.0", + family: 4, + } as any); + const result = await (service as any).hasInternetConnection(); + expect(result).toBe(false); + expect(dns.lookup).toHaveBeenCalledTimes(1); + }); + + it("returns false when DNS resolves to localhost", async () => { + const dns: any = (await import("dns/promises")).default; + dns.lookup.mockResolvedValueOnce({ + address: "127.0.0.1", + family: 4, + } as any); + const result = await (service as any).hasInternetConnection(); + expect(result).toBe(false); + expect(dns.lookup).toHaveBeenCalledTimes(1); + }); + + it("returns true when DNS resolves to valid address", async () => { + const dns: any = (await import("dns/promises")).default; + dns.lookup.mockResolvedValueOnce({ + address: "1.1.1.1", + family: 4, + } as any); + const result = await (service as any).hasInternetConnection(); + expect(result).toBe(true); + expect(dns.lookup).toHaveBeenCalledTimes(1); + }); }); }); diff --git a/extensions/cli/src/telemetry/posthogService.ts b/extensions/cli/src/telemetry/posthogService.ts index 1c2c66304..48363fbd7 100644 --- a/extensions/cli/src/telemetry/posthogService.ts +++ b/extensions/cli/src/telemetry/posthogService.ts @@ -5,6 +5,7 @@ import node_machine_id from "node-machine-id"; import type { PostHog as PostHogType } from "posthog-node"; import { isAuthenticatedConfig, loadAuthConfig } from "../auth/workos.js"; +import { loggers } from "../logging.js"; import { isHeadlessMode, isServe } from "../util/cli.js"; import { isGitHubActions } from "../util/git.js"; import { logger } from "../util/logger.js"; @@ -13,6 +14,7 @@ import { getVersion } from "../version.js"; export class PosthogService { private _os: string | undefined; private _uniqueId: string | undefined; + private _telemetryBlocked: boolean = false; constructor() { // Initialization is now lazy to avoid issues with mocking in tests @@ -36,15 +38,24 @@ export class PosthogService { private async hasInternetConnection() { const refetchConnection = async () => { try { - await dns.lookup("app.posthog.com"); - this._hasInternetConnection = true; + const result = await dns.lookup("app.posthog.com"); + const isValidAddress = + result.address !== "0.0.0.0" && !result.address.startsWith("127."); + this._hasInternetConnection = isValidAddress; + this._telemetryBlocked = !isValidAddress; + if (!isValidAddress) { + logger.debug( + "DNS lookup returned invalid address for PostHog, skipping telemetry", + ); + } } catch { this._hasInternetConnection = false; + this._telemetryBlocked = false; } }; if (typeof this._hasInternetConnection !== "undefined") { - void refetchConnection(); // check in background if connection became available + void refetchConnection(); return this._hasInternetConnection; } @@ -53,6 +64,12 @@ export class PosthogService { } get isEnabled() { + if (process.env.CONTINUE_TELEMETRY_ENABLED === "0") { + return false; + } + if (process.env.CONTINUE_TELEMETRY_ENABLED === "1") { + return true; + } return process.env.CONTINUE_ALLOW_ANONYMOUS_TELEMETRY !== "0"; } @@ -60,7 +77,13 @@ export class PosthogService { private async getClient() { if (!(await this.hasInternetConnection())) { this._client = undefined; - logger.warn("No internet connection, skipping telemetry"); + if (this._telemetryBlocked && this.isEnabled) { + loggers.warning( + "Telemetry appears to be blocked by your network. To disable telemetry entirely, set CONTINUE_TELEMETRY_ENABLED=0", + ); + } else if (this.isEnabled) { + logger.warn("No internet connection, skipping telemetry"); + } } else if (this.isEnabled) { if (!this._client) { const { PostHog } = await import("posthog-node"); diff --git a/extensions/cli/src/telemetry/telemetryService.ts b/extensions/cli/src/telemetry/telemetryService.ts index 910c82f59..6cc2f18c9 100644 --- a/extensions/cli/src/telemetry/telemetryService.ts +++ b/extensions/cli/src/telemetry/telemetryService.ts @@ -71,8 +71,17 @@ class TelemetryService { process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT || process.env.OTEL_METRICS_EXPORTER ); - const enabled = - process.env.CONTINUE_CLI_ENABLE_TELEMETRY !== "0" && hasOtelConfig; + + let telemetryEnabled = true; + if (process.env.CONTINUE_TELEMETRY_ENABLED === "0") { + telemetryEnabled = false; + } else if (process.env.CONTINUE_TELEMETRY_ENABLED === "1") { + telemetryEnabled = true; + } else { + telemetryEnabled = process.env.CONTINUE_CLI_ENABLE_TELEMETRY !== "0"; + } + + const enabled = telemetryEnabled && hasOtelConfig; const sessionId = uuidv4(); return { From 64dbb9abde45379cd0b44ad62249a158d100bdd4 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Fri, 28 Nov 2025 18:41:49 +0530 Subject: [PATCH 2/6] rename to CONTINUE_METRICS_ENABLED --- extensions/cli/src/telemetry/telemetryService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/cli/src/telemetry/telemetryService.ts b/extensions/cli/src/telemetry/telemetryService.ts index 6cc2f18c9..5804a24bc 100644 --- a/extensions/cli/src/telemetry/telemetryService.ts +++ b/extensions/cli/src/telemetry/telemetryService.ts @@ -73,9 +73,9 @@ class TelemetryService { ); let telemetryEnabled = true; - if (process.env.CONTINUE_TELEMETRY_ENABLED === "0") { + if (process.env.CONTINUE_METRICS_ENABLED === "0") { telemetryEnabled = false; - } else if (process.env.CONTINUE_TELEMETRY_ENABLED === "1") { + } else if (process.env.CONTINUE_METRICS_ENABLED === "1") { telemetryEnabled = true; } else { telemetryEnabled = process.env.CONTINUE_CLI_ENABLE_TELEMETRY !== "0"; From f76f8efdc76e3a70bf31e3d2327fc9cdddf925c3 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Thu, 4 Dec 2025 18:24:50 +0530 Subject: [PATCH 3/6] update telemetry doc --- docs/telemetry.mdx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/telemetry.mdx b/docs/telemetry.mdx index b566d046b..44559cb2d 100644 --- a/docs/telemetry.mdx +++ b/docs/telemetry.mdx @@ -36,15 +36,17 @@ Alternatively in VS Code, you can disable telemetry through your VS Code setting ### CLI -For `cn`, the Continue CLI, set the environment variable `CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0` before running commands: +For `cn`, the Continue CLI, set the environment variable `CONTINUE_TELEMETRY_ENABLED=0` before running commands: ```bash -export CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0 +export CONTINUE_TELEMETRY_ENABLED=0 cn ``` Or run it inline: ```bash -CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0 cn +CONTINUE_TELEMETRY_ENABLED=0 cn ``` + +Note: The legacy `CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0` is still supported but `CONTINUE_TELEMETRY_ENABLED` takes precedence. From 8502fab7f628257a1ea2b0cf713c4edfe190e7d3 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Thu, 4 Dec 2025 18:26:30 +0530 Subject: [PATCH 4/6] update cli/spec --- extensions/cli/spec/otlp-metrics.md | 23 ++++++++++++----------- extensions/cli/spec/telemtry.md | 3 ++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/extensions/cli/spec/otlp-metrics.md b/extensions/cli/spec/otlp-metrics.md index a3900f700..af3e2e703 100644 --- a/extensions/cli/spec/otlp-metrics.md +++ b/extensions/cli/spec/otlp-metrics.md @@ -17,17 +17,18 @@ The Continue CLI should emit metrics that provide insights into: ### Environment Variables -| Environment Variable | Description | Example Values | -| ------------------------------- | --------------------------------------------------------- | ------------------------------------ | -| `CONTINUE_CLI_ENABLE_TELEMETRY` | Enables OTEL telemetry collection (required) | `1` | -| `OTEL_METRICS_EXPORTER` | Metrics exporter type(s) (comma-separated) | `console`, `otlp`, `prometheus` | -| `OTEL_LOGS_EXPORTER` | Logs/events exporter type(s) (comma-separated) | `console`, `otlp` | -| `OTEL_EXPORTER_OTLP_PROTOCOL` | Protocol for OTLP exporter (all signals) | `grpc`, `http/json`, `http/protobuf` | -| `OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP collector endpoint (all signals) | `http://localhost:4317` | -| `OTEL_EXPORTER_OTLP_HEADERS` | Authentication headers for OTLP | `Authorization=Bearer token` | -| `OTEL_METRIC_EXPORT_INTERVAL` | Export interval in milliseconds (default: 60000) | `5000`, `60000` | -| `OTEL_LOGS_EXPORT_INTERVAL` | Logs export interval in milliseconds (default: 5000) | `1000`, `10000` | -| `OTEL_LOG_USER_PROMPTS` | Enable logging of user prompt content (default: disabled) | `1` to enable | +| Environment Variable | Description | Example Values | +| ------------------------------- | --------------------------------------------------------------- | ------------------------------------ | +| `CONTINUE_METRICS_ENABLED` | Enables OTEL telemetry collection (preferred, takes precedence) | `0` to disable, `1` to enable | +| `CONTINUE_CLI_ENABLE_TELEMETRY` | Enables OTEL telemetry collection (legacy, lower precedence) | `0` to disable, `1` to enable | +| `OTEL_METRICS_EXPORTER` | Metrics exporter type(s) (comma-separated) | `console`, `otlp`, `prometheus` | +| `OTEL_LOGS_EXPORTER` | Logs/events exporter type(s) (comma-separated) | `console`, `otlp` | +| `OTEL_EXPORTER_OTLP_PROTOCOL` | Protocol for OTLP exporter (all signals) | `grpc`, `http/json`, `http/protobuf` | +| `OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP collector endpoint (all signals) | `http://localhost:4317` | +| `OTEL_EXPORTER_OTLP_HEADERS` | Authentication headers for OTLP | `Authorization=Bearer token` | +| `OTEL_METRIC_EXPORT_INTERVAL` | Export interval in milliseconds (default: 60000) | `5000`, `60000` | +| `OTEL_LOGS_EXPORT_INTERVAL` | Logs export interval in milliseconds (default: 5000) | `1000`, `10000` | +| `OTEL_LOG_USER_PROMPTS` | Enable logging of user prompt content (default: disabled) | `1` to enable | ### Metrics Cardinality Control diff --git a/extensions/cli/spec/telemtry.md b/extensions/cli/spec/telemtry.md index e5f4d76f8..6cc993643 100644 --- a/extensions/cli/spec/telemtry.md +++ b/extensions/cli/spec/telemtry.md @@ -4,7 +4,8 @@ - Used by Continue for product metrics (not used by customers) - uses public posthog key in repo -- CONTINUE_ALLOW_ANONYMOUS_TELEMETRY can be set to 0 to disable +- `CONTINUE_TELEMETRY_ENABLED=0` disables telemetry (preferred) +- `CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0` also disables telemetry (legacy, lower precedence) - non-anonymous and private data like code is never sent to posthog - Event user ids are the Continue user id is signed in, or a unique machine id if not - Current events are slash command usage and chat calls From 6d0d6e67fd41fa6a792e570249f0d97cd05e1fe6 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Thu, 4 Dec 2025 18:26:42 +0530 Subject: [PATCH 5/6] revert a comment --- extensions/cli/src/telemetry/posthogService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/cli/src/telemetry/posthogService.ts b/extensions/cli/src/telemetry/posthogService.ts index 48363fbd7..775915549 100644 --- a/extensions/cli/src/telemetry/posthogService.ts +++ b/extensions/cli/src/telemetry/posthogService.ts @@ -55,7 +55,7 @@ export class PosthogService { }; if (typeof this._hasInternetConnection !== "undefined") { - void refetchConnection(); + void refetchConnection(); // check in background if connection became available return this._hasInternetConnection; } From a080b635b473a81f7892a5b6745ec87117a8d08b Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Thu, 4 Dec 2025 12:10:35 -0800 Subject: [PATCH 6/6] docs: remove legacy env var notes --- docs/telemetry.mdx | 4 +--- extensions/cli/spec/telemtry.md | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/docs/telemetry.mdx b/docs/telemetry.mdx index 44559cb2d..12dc39bf2 100644 --- a/docs/telemetry.mdx +++ b/docs/telemetry.mdx @@ -47,6 +47,4 @@ Or run it inline: ```bash CONTINUE_TELEMETRY_ENABLED=0 cn -``` - -Note: The legacy `CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0` is still supported but `CONTINUE_TELEMETRY_ENABLED` takes precedence. +``` \ No newline at end of file diff --git a/extensions/cli/spec/telemtry.md b/extensions/cli/spec/telemtry.md index 6cc993643..8c3a1796d 100644 --- a/extensions/cli/spec/telemtry.md +++ b/extensions/cli/spec/telemtry.md @@ -4,8 +4,7 @@ - Used by Continue for product metrics (not used by customers) - uses public posthog key in repo -- `CONTINUE_TELEMETRY_ENABLED=0` disables telemetry (preferred) -- `CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0` also disables telemetry (legacy, lower precedence) +- `CONTINUE_TELEMETRY_ENABLED=0` disables telemetry - non-anonymous and private data like code is never sent to posthog - Event user ids are the Continue user id is signed in, or a unique machine id if not - Current events are slash command usage and chat calls