From 2a07966d2bc40d1b3cf2b8fbe950edc27aef5a58 Mon Sep 17 00:00:00 2001
From: Nate Sesti <sestinj@gmail.com>
Date: Fri, 21 Jul 2023 19:55:08 -0700
Subject: remove Segment telemetry from React

---
 extension/src/activation/activate.ts         |  1 -
 extension/src/activation/environmentSetup.ts | 17 +--------
 extension/src/continueIdeClient.ts           | 20 +++++------
 extension/src/suggestions.ts                 |  3 --
 extension/src/telemetry.ts                   | 53 ----------------------------
 5 files changed, 11 insertions(+), 83 deletions(-)
 delete mode 100644 extension/src/telemetry.ts

(limited to 'extension/src')

diff --git a/extension/src/activation/activate.ts b/extension/src/activation/activate.ts
index a7f6c55b..65f026d8 100644
--- a/extension/src/activation/activate.ts
+++ b/extension/src/activation/activate.ts
@@ -1,7 +1,6 @@
 import * as vscode from "vscode";
 import { registerAllCommands } from "../commands";
 import { registerAllCodeLensProviders } from "../lang-server/codeLens";
-import { sendTelemetryEvent, TelemetryEvent } from "../telemetry";
 import IdeProtocolClient from "../continueIdeClient";
 import { getContinueServerUrl } from "../bridge";
 import { ContinueGUIWebviewViewProvider } from "../debugPanel";
diff --git a/extension/src/activation/environmentSetup.ts b/extension/src/activation/environmentSetup.ts
index 94481430..5a9345a6 100644
--- a/extension/src/activation/environmentSetup.ts
+++ b/extension/src/activation/environmentSetup.ts
@@ -9,7 +9,6 @@ import fetch from "node-fetch";
 import * as vscode from "vscode";
 import * as os from "os";
 import fkill from "fkill";
-import { sendTelemetryEvent, TelemetryEvent } from "../telemetry";
 
 const WINDOWS_REMOTE_SIGNED_SCRIPTS_ERROR =
   "A Python virtual enviroment cannot be activated because running scripts is disabled for this user. In order to use Continue, please enable signed scripts to run with this command in PowerShell: `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser`, reload VS Code, and then try again.";
@@ -57,9 +56,6 @@ async function retryThenFail(
       vscode.window.showErrorMessage(msg);
     }
 
-    sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, {
-      error: e.message,
-    });
     throw e;
   }
 }
@@ -83,12 +79,6 @@ async function runCommand(cmd: string): Promise<[string, string | undefined]> {
     stdout = "";
   }
 
-  if (stderr) {
-    sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, {
-      error: stderr,
-    });
-  }
-
   return [stdout, stderr];
 }
 
@@ -480,16 +470,11 @@ export async function startContinuePythonServer() {
             console.log("Successfully started Continue python server");
             resolve(null);
           } else if (data.includes("ERROR") || data.includes("Traceback")) {
-            sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, {
-              error: data,
-            });
+            console.log("Error starting Continue python server: ", data);
           }
         });
         child.on("error", (error: any) => {
           console.log(`error: ${error.message}`);
-          sendTelemetryEvent(TelemetryEvent.ExtensionSetupError, {
-            error: error.message,
-          });
         });
 
         // Write the current version of vscode to a file called server_version.txt
diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts
index 3a42e773..802afc1d 100644
--- a/extension/src/continueIdeClient.ts
+++ b/extension/src/continueIdeClient.ts
@@ -16,7 +16,6 @@ import fs = require("fs");
 import { WebsocketMessenger } from "./util/messenger";
 import { diffManager } from "./diffs";
 import path = require("path");
-import { sendTelemetryEvent, TelemetryEvent } from "./telemetry";
 import { registerAllCodeLensProviders } from "./lang-server/codeLens";
 import { registerAllCommands } from "./commands";
 import registerQuickFixProvider from "./lang-server/codeActions";
@@ -81,7 +80,6 @@ class IdeProtocolClient {
     this._newWebsocketMessenger();
 
     // Register commands and providers
-    sendTelemetryEvent(TelemetryEvent.ExtensionActivated);
     registerAllCodeLensProviders(context);
     registerAllCommands(context);
     registerQuickFixProvider();
@@ -171,14 +169,16 @@ class IdeProtocolClient {
     // Listen for changes to settings.json
     vscode.workspace.onDidChangeConfiguration((event) => {
       if (event.affectsConfiguration("continue")) {
-        vscode.window.showInformationMessage(
-          "Please reload VS Code for changes to Continue settings to take effect.",
-          "Reload"
-        ).then((selection) => {
-          if (selection === "Reload") {
-            vscode.commands.executeCommand("workbench.action.reloadWindow");
-          }
-        });
+        vscode.window
+          .showInformationMessage(
+            "Please reload VS Code for changes to Continue settings to take effect.",
+            "Reload"
+          )
+          .then((selection) => {
+            if (selection === "Reload") {
+              vscode.commands.executeCommand("workbench.action.reloadWindow");
+            }
+          });
       }
     });
   }
diff --git a/extension/src/suggestions.ts b/extension/src/suggestions.ts
index c2373223..5c2b8860 100644
--- a/extension/src/suggestions.ts
+++ b/extension/src/suggestions.ts
@@ -1,5 +1,4 @@
 import * as vscode from "vscode";
-import { sendTelemetryEvent, TelemetryEvent } from "./telemetry";
 import { openEditorAndRevealRange } from "./util/vscode";
 import { translate } from "./util/vscode";
 import { registerAllCodeLensProviders } from "./lang-server/codeLens";
@@ -244,7 +243,6 @@ function selectSuggestion(
 }
 
 export function acceptSuggestionCommand(key: SuggestionRanges | null = null) {
-  sendTelemetryEvent(TelemetryEvent.SuggestionAccepted);
   selectSuggestion("selected", key);
 }
 
@@ -271,7 +269,6 @@ export function rejectAllSuggestionsCommand() {
 export async function rejectSuggestionCommand(
   key: SuggestionRanges | null = null
 ) {
-  sendTelemetryEvent(TelemetryEvent.SuggestionRejected);
   selectSuggestion("old", key);
 }
 
diff --git a/extension/src/telemetry.ts b/extension/src/telemetry.ts
deleted file mode 100644
index db5cb8ca..00000000
--- a/extension/src/telemetry.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-import * as Segment from "@segment/analytics-node";
-import * as vscode from "vscode";
-
-// Setup Segment
-const SEGMENT_WRITE_KEY = "57yy2uYXH2bwMuy7djm9PorfFlYqbJL1";
-const analytics = new Segment.Analytics({ writeKey: SEGMENT_WRITE_KEY });
-analytics.identify({
-  userId: vscode.env.machineId,
-  //   traits: {
-  //     name: "Michael Bolton",
-  //     email: "mbolton@example.com",
-  //     createdAt: new Date("2014-06-14T02:00:19.467Z"),
-  //   },
-});
-
-// Enum of telemetry events
-export enum TelemetryEvent {
-  // Extension has been activated
-  ExtensionActivated = "ExtensionActivated",
-  // Suggestion has been accepted
-  SuggestionAccepted = "SuggestionAccepted",
-  // Suggestion has been rejected
-  SuggestionRejected = "SuggestionRejected",
-  // Queried universal prompt
-  UniversalPromptQuery = "UniversalPromptQuery",
-  // `Explain Code` button clicked
-  ExplainCode = "ExplainCode",
-  // `Generate Ideas` button clicked
-  GenerateIdeas = "GenerateIdeas",
-  // `Suggest Fix` button clicked
-  SuggestFix = "SuggestFix",
-  // `Create Test` button clicked
-  CreateTest = "CreateTest",
-  // `AutoDebug This Test` button clicked
-  AutoDebugThisTest = "AutoDebugThisTest",
-  // Command run to generate docstring
-  GenerateDocstring = "GenerateDocstring",
-  // Error setting up the extension
-  ExtensionSetupError = "ExtensionSetupError",
-}
-
-export function sendTelemetryEvent(
-  event: TelemetryEvent,
-  properties?: Record<string, any>
-) {
-  if (!vscode.env.isTelemetryEnabled) return;
-
-  analytics.track({
-    event,
-    userId: vscode.env.machineId,
-    properties,
-  });
-}
-- 
cgit v1.2.3-70-g09d2