Skip to content

Commit 34fdeb8

Browse files
authored
Merge pull request #8925 from uinstinct/renamed-envvars
fix: use more intuitive envvars to manage OTLP and PostHog telemetry settings
2 parents 37b4702 + a080b63 commit 34fdeb8

File tree

6 files changed

+87
-21
lines changed

6 files changed

+87
-21
lines changed

docs/telemetry.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ Alternatively in VS Code, you can disable telemetry through your VS Code setting
3636

3737
### CLI
3838

39-
For `cn`, the Continue CLI, set the environment variable `CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0` before running commands:
39+
For `cn`, the Continue CLI, set the environment variable `CONTINUE_TELEMETRY_ENABLED=0` before running commands:
4040

4141
```bash
42-
export CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0
42+
export CONTINUE_TELEMETRY_ENABLED=0
4343
cn <your prompt>
4444
```
4545

4646
Or run it inline:
4747

4848
```bash
49-
CONTINUE_ALLOW_ANONYMOUS_TELEMETRY=0 cn <your prompt>
50-
```
49+
CONTINUE_TELEMETRY_ENABLED=0 cn <your prompt>
50+
```

extensions/cli/spec/otlp-metrics.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ The Continue CLI should emit metrics that provide insights into:
1717

1818
### Environment Variables
1919

20-
| Environment Variable | Description | Example Values |
21-
| ------------------------------- | --------------------------------------------------------- | ------------------------------------ |
22-
| `CONTINUE_CLI_ENABLE_TELEMETRY` | Enables OTEL telemetry collection (required) | `1` |
23-
| `OTEL_METRICS_EXPORTER` | Metrics exporter type(s) (comma-separated) | `console`, `otlp`, `prometheus` |
24-
| `OTEL_LOGS_EXPORTER` | Logs/events exporter type(s) (comma-separated) | `console`, `otlp` |
25-
| `OTEL_EXPORTER_OTLP_PROTOCOL` | Protocol for OTLP exporter (all signals) | `grpc`, `http/json`, `http/protobuf` |
26-
| `OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP collector endpoint (all signals) | `http://localhost:4317` |
27-
| `OTEL_EXPORTER_OTLP_HEADERS` | Authentication headers for OTLP | `Authorization=Bearer token` |
28-
| `OTEL_METRIC_EXPORT_INTERVAL` | Export interval in milliseconds (default: 60000) | `5000`, `60000` |
29-
| `OTEL_LOGS_EXPORT_INTERVAL` | Logs export interval in milliseconds (default: 5000) | `1000`, `10000` |
30-
| `OTEL_LOG_USER_PROMPTS` | Enable logging of user prompt content (default: disabled) | `1` to enable |
20+
| Environment Variable | Description | Example Values |
21+
| ------------------------------- | --------------------------------------------------------------- | ------------------------------------ |
22+
| `CONTINUE_METRICS_ENABLED` | Enables OTEL telemetry collection (preferred, takes precedence) | `0` to disable, `1` to enable |
23+
| `CONTINUE_CLI_ENABLE_TELEMETRY` | Enables OTEL telemetry collection (legacy, lower precedence) | `0` to disable, `1` to enable |
24+
| `OTEL_METRICS_EXPORTER` | Metrics exporter type(s) (comma-separated) | `console`, `otlp`, `prometheus` |
25+
| `OTEL_LOGS_EXPORTER` | Logs/events exporter type(s) (comma-separated) | `console`, `otlp` |
26+
| `OTEL_EXPORTER_OTLP_PROTOCOL` | Protocol for OTLP exporter (all signals) | `grpc`, `http/json`, `http/protobuf` |
27+
| `OTEL_EXPORTER_OTLP_ENDPOINT` | OTLP collector endpoint (all signals) | `http://localhost:4317` |
28+
| `OTEL_EXPORTER_OTLP_HEADERS` | Authentication headers for OTLP | `Authorization=Bearer token` |
29+
| `OTEL_METRIC_EXPORT_INTERVAL` | Export interval in milliseconds (default: 60000) | `5000`, `60000` |
30+
| `OTEL_LOGS_EXPORT_INTERVAL` | Logs export interval in milliseconds (default: 5000) | `1000`, `10000` |
31+
| `OTEL_LOG_USER_PROMPTS` | Enable logging of user prompt content (default: disabled) | `1` to enable |
3132

3233
### Metrics Cardinality Control
3334

extensions/cli/spec/telemtry.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- Used by Continue for product metrics (not used by customers)
66
- uses public posthog key in repo
7-
- CONTINUE_ALLOW_ANONYMOUS_TELEMETRY can be set to 0 to disable
7+
- `CONTINUE_TELEMETRY_ENABLED=0` disables telemetry
88
- non-anonymous and private data like code is never sent to posthog
99
- Event user ids are the Continue user id is signed in, or a unique machine id if not
1010
- Current events are slash command usage and chat calls

extensions/cli/src/telemetry/posthogService.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,5 +152,38 @@ describe("PosthogService", () => {
152152
expect(client).toBeUndefined();
153153
expect(dns.lookup).toHaveBeenCalledTimes(1);
154154
});
155+
156+
it("returns false when DNS resolves to 0.0.0.0 (blocked)", async () => {
157+
const dns: any = (await import("dns/promises")).default;
158+
dns.lookup.mockResolvedValueOnce({
159+
address: "0.0.0.0",
160+
family: 4,
161+
} as any);
162+
const result = await (service as any).hasInternetConnection();
163+
expect(result).toBe(false);
164+
expect(dns.lookup).toHaveBeenCalledTimes(1);
165+
});
166+
167+
it("returns false when DNS resolves to localhost", async () => {
168+
const dns: any = (await import("dns/promises")).default;
169+
dns.lookup.mockResolvedValueOnce({
170+
address: "127.0.0.1",
171+
family: 4,
172+
} as any);
173+
const result = await (service as any).hasInternetConnection();
174+
expect(result).toBe(false);
175+
expect(dns.lookup).toHaveBeenCalledTimes(1);
176+
});
177+
178+
it("returns true when DNS resolves to valid address", async () => {
179+
const dns: any = (await import("dns/promises")).default;
180+
dns.lookup.mockResolvedValueOnce({
181+
address: "1.1.1.1",
182+
family: 4,
183+
} as any);
184+
const result = await (service as any).hasInternetConnection();
185+
expect(result).toBe(true);
186+
expect(dns.lookup).toHaveBeenCalledTimes(1);
187+
});
155188
});
156189
});

extensions/cli/src/telemetry/posthogService.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import node_machine_id from "node-machine-id";
55
import type { PostHog as PostHogType } from "posthog-node";
66

77
import { isAuthenticatedConfig, loadAuthConfig } from "../auth/workos.js";
8+
import { loggers } from "../logging.js";
89
import { isHeadlessMode, isServe } from "../util/cli.js";
910
import { isGitHubActions } from "../util/git.js";
1011
import { logger } from "../util/logger.js";
@@ -13,6 +14,7 @@ import { getVersion } from "../version.js";
1314
export class PosthogService {
1415
private _os: string | undefined;
1516
private _uniqueId: string | undefined;
17+
private _telemetryBlocked: boolean = false;
1618

1719
constructor() {
1820
// Initialization is now lazy to avoid issues with mocking in tests
@@ -36,10 +38,19 @@ export class PosthogService {
3638
private async hasInternetConnection() {
3739
const refetchConnection = async () => {
3840
try {
39-
await dns.lookup("app.posthog.com");
40-
this._hasInternetConnection = true;
41+
const result = await dns.lookup("app.posthog.com");
42+
const isValidAddress =
43+
result.address !== "0.0.0.0" && !result.address.startsWith("127.");
44+
this._hasInternetConnection = isValidAddress;
45+
this._telemetryBlocked = !isValidAddress;
46+
if (!isValidAddress) {
47+
logger.debug(
48+
"DNS lookup returned invalid address for PostHog, skipping telemetry",
49+
);
50+
}
4151
} catch {
4252
this._hasInternetConnection = false;
53+
this._telemetryBlocked = false;
4354
}
4455
};
4556

@@ -53,14 +64,26 @@ export class PosthogService {
5364
}
5465

5566
get isEnabled() {
67+
if (process.env.CONTINUE_TELEMETRY_ENABLED === "0") {
68+
return false;
69+
}
70+
if (process.env.CONTINUE_TELEMETRY_ENABLED === "1") {
71+
return true;
72+
}
5673
return process.env.CONTINUE_ALLOW_ANONYMOUS_TELEMETRY !== "0";
5774
}
5875

5976
private _client: PostHogType | undefined;
6077
private async getClient() {
6178
if (!(await this.hasInternetConnection())) {
6279
this._client = undefined;
63-
logger.warn("No internet connection, skipping telemetry");
80+
if (this._telemetryBlocked && this.isEnabled) {
81+
loggers.warning(
82+
"Telemetry appears to be blocked by your network. To disable telemetry entirely, set CONTINUE_TELEMETRY_ENABLED=0",
83+
);
84+
} else if (this.isEnabled) {
85+
logger.warn("No internet connection, skipping telemetry");
86+
}
6487
} else if (this.isEnabled) {
6588
if (!this._client) {
6689
const { PostHog } = await import("posthog-node");

extensions/cli/src/telemetry/telemetryService.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ class TelemetryService {
7171
process.env.OTEL_EXPORTER_OTLP_METRICS_ENDPOINT ||
7272
process.env.OTEL_METRICS_EXPORTER
7373
);
74-
const enabled =
75-
process.env.CONTINUE_CLI_ENABLE_TELEMETRY !== "0" && hasOtelConfig;
74+
75+
let telemetryEnabled = true;
76+
if (process.env.CONTINUE_METRICS_ENABLED === "0") {
77+
telemetryEnabled = false;
78+
} else if (process.env.CONTINUE_METRICS_ENABLED === "1") {
79+
telemetryEnabled = true;
80+
} else {
81+
telemetryEnabled = process.env.CONTINUE_CLI_ENABLE_TELEMETRY !== "0";
82+
}
83+
84+
const enabled = telemetryEnabled && hasOtelConfig;
7685
const sessionId = uuidv4();
7786

7887
return {

0 commit comments

Comments
 (0)