@@ -5,6 +5,7 @@ import node_machine_id from "node-machine-id";
55import type { PostHog as PostHogType } from "posthog-node" ;
66
77import { isAuthenticatedConfig , loadAuthConfig } from "../auth/workos.js" ;
8+ import { loggers } from "../logging.js" ;
89import { isHeadlessMode , isServe } from "../util/cli.js" ;
910import { isGitHubActions } from "../util/git.js" ;
1011import { logger } from "../util/logger.js" ;
@@ -13,6 +14,7 @@ import { getVersion } from "../version.js";
1314export 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" ) ;
0 commit comments