This commit is contained in:
Logan Ramos 2022-01-20 14:45:06 -05:00
Родитель ca6ce07ec8
Коммит ab7345e89b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: D9CCFF14F0B18183
4 изменённых файлов: 58 добавлений и 10 удалений

Просмотреть файл

@ -34,7 +34,7 @@ const webAppInsightsClientFactory = async (key: string): Promise<BaseTelemetryCl
// If we cannot access the endpoint this most likely means it's being blocked
// and we should not attempt to send any telemetry.
const telemetryLevel = getTelemetryLevel();
if (endpointUrl && telemetryLevel === TelemetryLevel.ON) {
if (endpointUrl && telemetryLevel !== TelemetryLevel.OFF) {
fetch(endpointUrl).catch(() => (appInsightsClient = undefined));
}
} catch (e) {

Просмотреть файл

@ -49,7 +49,7 @@ export class BaseTelemetryReporter {
private updateUserOptStatus(): void {
const telemetryLevel = getTelemetryLevel();
this.userOptIn = telemetryLevel === TelemetryLevel.ON;
this.errorOptIn = telemetryLevel === TelemetryLevel.ON;
this.errorOptIn = telemetryLevel === TelemetryLevel.ERROR || this.userOptIn;
if (this.userOptIn || this.errorOptIn) {
this.telemetryAppender.instantiateAppender();
}

Просмотреть файл

@ -6,6 +6,7 @@ import * as vscode from "vscode";
export const enum TelemetryLevel {
ON = "on",
ERROR = "error",
OFF = "off"
}
@ -13,13 +14,24 @@ export function getTelemetryLevel(): TelemetryLevel {
const TELEMETRY_CONFIG_ID = "telemetry";
const TELEMETRY_CONFIG_ENABLED_ID = "enableTelemetry";
// Could be undefined in old versions of vs code
if (vscode.env.isTelemetryEnabled !== undefined) {
return vscode.env.isTelemetryEnabled ? TelemetryLevel.ON : TelemetryLevel.OFF;
}
try {
const telemetryConfiguration = vscode.env.telemetryConfiguration;
if (telemetryConfiguration.isUsageEnabled) {
return TelemetryLevel.ON;
} else if (telemetryConfiguration.isErrorsEnabled) {
return TelemetryLevel.ERROR;
} else {
return TelemetryLevel.OFF;
}
} catch {
// Could be undefined in old versions of vs code
if (vscode.env.isTelemetryEnabled !== undefined) {
return vscode.env.isTelemetryEnabled ? TelemetryLevel.ON : TelemetryLevel.OFF;
}
// We use the old and new setting to determine the telemetry level as we must respect both
const config = vscode.workspace.getConfiguration(TELEMETRY_CONFIG_ID);
const enabled = config.get<boolean>(TELEMETRY_CONFIG_ENABLED_ID);
return enabled ? TelemetryLevel.ON : TelemetryLevel.OFF;
// We use the old and new setting to determine the telemetry level as we must respect both
const config = vscode.workspace.getConfiguration(TELEMETRY_CONFIG_ID);
const enabled = config.get<boolean>(TELEMETRY_CONFIG_ENABLED_ID);
return enabled ? TelemetryLevel.ON : TelemetryLevel.OFF;
}
}

36
vscode.proposed.telemetry.d.ts поставляемый Normal file
Просмотреть файл

@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'vscode' {
export interface TelemetryConfiguration {
/**
* Whether or not usage telemetry collection is allowed
*/
isUsageEnabled: boolean;
/**
* Whether or not crash error telemetry collection is allowed
*/
isErrorsEnabled: boolean;
/**
* Whether or not crash report collection is allowed
*/
isCrashEnabled: boolean;
}
export namespace env {
/**
* Indicates what telemetry is enabled / disabled
* Can be observed to determine what telemetry the extension is allowed to send
*/
export const telemetryConfiguration: TelemetryConfiguration;
/**
* An {@link Event} which fires when the collectable state of telemetry changes
* Returns a {@link TelemetryConfiguration} object
*/
export const onDidChangeTelemetryConfiguration: Event<TelemetryConfiguration | undefined>;
}
}