diff --git a/.github/labeler.yml b/.github/labeler.yml index 26c23e3..66de71e 100644 --- a/.github/labeler.yml +++ b/.github/labeler.yml @@ -11,7 +11,7 @@ - src/quack.ts "module: telemetry": - - src/telemetry.ts + - src/analytics.ts "module: util": - src/util/* diff --git a/src/telemetry.ts b/src/analytics.ts similarity index 73% rename from src/telemetry.ts rename to src/analytics.ts index bbf3cf1..2dbdc66 100644 --- a/src/telemetry.ts +++ b/src/analytics.ts @@ -8,7 +8,7 @@ import { PostHog } from "posthog-node"; import * as path from "path"; import * as dotenv from "dotenv"; -let telemetryClient: PostHog | null = null; +let analyticsClient: PostHog | null = null; const telemetryLevel: string = vscode.workspace .getConfiguration("telemetry") .get("telemetryLevel", "all"); @@ -17,11 +17,15 @@ const telemetryLevel: string = vscode.workspace const envPath = path.join(path.dirname(__dirname), ".env"); dotenv.config({ path: envPath }); -if (process.env.POSTHOG_KEY && telemetryLevel === "all") { - telemetryClient = new PostHog(process.env.POSTHOG_KEY, { +if ( + process.env.POSTHOG_KEY && + vscode.env.isTelemetryEnabled && + telemetryLevel === "all" +) { + analyticsClient = new PostHog(process.env.POSTHOG_KEY, { host: process.env.POSTHOG_HOST, }); console.log("Collecting anonymized usage data"); } -export default telemetryClient; +export default analyticsClient; diff --git a/src/extension.ts b/src/extension.ts index 0215d50..d86e7f9 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -11,7 +11,7 @@ import { GuidelineTreeItem, GuidelineTreeProvider, } from "./webviews/guidelineView"; -import telemetryClient from "./telemetry"; +import analyticsClient from "./analytics"; import { getCurrentRepoName, getSelectionText, @@ -131,7 +131,7 @@ export async function activate(context: vscode.ExtensionContext) { } // Telemetry - telemetryClient?.capture({ + analyticsClient?.capture({ distinctId: userId, event: "vscode-fetch-guidelines", properties: { @@ -257,7 +257,7 @@ export async function activate(context: vscode.ExtensionContext) { // console.log(vscode.window.activeTextEditor?.document.languageId); // Telemetry - telemetryClient?.capture({ + analyticsClient?.capture({ distinctId: userId, event: "vscode-analyze-code", properties: { @@ -329,7 +329,7 @@ export async function activate(context: vscode.ExtensionContext) { diagnosticCollection.set(getEditor().document.uri, diagnostics); statusBarItem.dispose(); // Telemetry - telemetryClient?.capture({ + analyticsClient?.capture({ distinctId: userId, event: "vscode-analyze-code-mono", properties: { @@ -420,5 +420,5 @@ export async function activate(context: vscode.ExtensionContext) { } export function deactivate() { - telemetryClient?.shutdownAsync(); + analyticsClient?.shutdownAsync(); }