Skip to content

Commit

Permalink
Do not use readSync everytime telemetry is sent
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Mar 1, 2024
1 parent 999f7e7 commit 06669db
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/client/telemetry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// Licensed under the MIT License.

import TelemetryReporter from '@vscode/extension-telemetry';

import * as path from 'path';
import * as fs from 'fs-extra';
import * as vscode from 'vscode';
import { DiagnosticCodes } from '../application/diagnostics/constants';
import { AppinsightsKey, EXTENSION_ROOT_DIR, isTestExecution, isUnitTestExecution } from '../common/constants';
import { AppinsightsKey, isTestExecution, isUnitTestExecution, PVSC_EXTENSION_ID } from '../common/constants';
import type { TerminalShellType } from '../common/terminal/types';
import { StopWatch } from '../common/utils/stopWatch';
import { isPromise } from '../common/utils/async';
Expand Down Expand Up @@ -39,14 +37,19 @@ function isTelemetrySupported(): boolean {
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let packageJSON: any;

/**
* Checks if the telemetry is disabled
* @returns {boolean}
*/
export function isTelemetryDisabled(): boolean {
const packageJsonPath = path.join(EXTENSION_ROOT_DIR, 'package.json');
const packageJson = fs.readJSONSync(packageJsonPath);
return !packageJson.enableTelemetry;
if (!packageJSON) {
const pythonExtension = vscode.extensions.getExtension(PVSC_EXTENSION_ID)!;
packageJSON = pythonExtension.packageJSON;
}
return !packageJSON.enableTelemetry;
}

const sharedProperties: Record<string, unknown> = {};
Expand Down

0 comments on commit 06669db

Please sign in to comment.