Add Warning if we fail to disable SDK Telemetry

This commit is contained in:
Noah Gilson 2023-10-18 16:48:15 -07:00
Родитель 919442fb0d
Коммит 8e06ab0b41
14 изменённых файлов: 65 добавлений и 23 удалений

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

@ -70,11 +70,13 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE
extensionContext.extensionConfiguration :
vscode.workspace.getConfiguration(configPrefix);
const extensionTelemetryEnabled = enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry);
const eventStreamContext = {
displayChannelName,
logPath: context.logPath,
extensionId: dotnetCoreAcquisitionExtensionId,
enableTelemetry: enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry),
enableTelemetry: extensionTelemetryEnabled,
telemetryReporter: extensionContext ? extensionContext.telemetryReporter : undefined,
showLogCommand: `${commandPrefix}.${commandKeys.showAcquisitionLog}`,
packageJson,
@ -112,7 +114,8 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE
installationValidator: new InstallationValidator(eventStream),
timeoutValue: resolvedTimeoutSeconds,
installDirectoryProvider: new RuntimeInstallationDirectoryProvider(context.globalStoragePath),
proxyUrl: proxyLink
proxyUrl: proxyLink,
isExtensionTelemetryInitiallyEnabled: extensionTelemetryEnabled
});
const existingPathResolver = new ExistingPathResolver();
const versionResolver = new VersionResolver(context.globalState, eventStream, resolvedTimeoutSeconds, proxyLink);
@ -197,4 +200,5 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE
ensureDependenciesRegistration,
reportIssueRegistration,
...eventStreamObservers);
}

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

@ -40,7 +40,7 @@ export function registerEventStream(context: IEventStreamContext): [EventStream,
const logFile = path.join(context.logPath, `DotNetAcquisition-${context.extensionId}-${ new Date().getTime() }.txt`);
const loggingObserver = new LoggingObserver(logFile);
let eventStreamObservers: IEventStreamObserver[] =
const eventStreamObservers: IEventStreamObserver[] =
[
new StatusBarObserver(vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.MIN_VALUE), context.showLogCommand),
new OutputChannelObserver(outputChannel),

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

@ -80,7 +80,11 @@ export class TelemetryObserver implements IEventStreamObserver {
if(!TelemetryObserver.isTelemetryEnabled(isExtensionTelemetryEnabled))
{
TelemetryObserver.logTelemetryChange(`Before disabling .NET SDK telemetry:`, isExtensionTelemetryEnabled, eventStream);
new CommandExecutor(eventStream).setEnvironmentVariable('DOTNET_CLI_TELEMETRY_OPTOUT', 'true');
new CommandExecutor(eventStream).setEnvironmentVariable('DOTNET_CLI_TELEMETRY_OPTOUT', 'true',
`Telemetry is disabled for VS Code & the .NET Install Tool Extension, but the .NET SDK extension may still collect telemetry and we may not have successfully turned it off.
Please verify that .NET SDK telemetry is disabled by setting the environment variable DOTNET_CLI_TELEMETRY_OPTOUT to true.`);
TelemetryObserver.logTelemetryChange(`After disabling .NET SDK telemetry:`, isExtensionTelemetryEnabled, eventStream);
}
else

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

@ -22,6 +22,7 @@ import path = require('path');
import { IEventStream } from '../EventStream/EventStream';
import * as vscode from 'vscode';
import * as os from 'os';
import { WindowDisplayWorker } from '../EventStream/WindowDisplayWorker';
/* tslint:disable:no-any */
@ -211,21 +212,51 @@ out: ${commandResult.stdout} err: ${commandResult.stderr}.`));
return [workingCommand, working];
}
public async setEnvironmentVariable(variable : string, value : string)
public async setEnvironmentVariable(variable : string, value : string, failureWarningMessage? : string)
{
// todo: verify this works on all os
const oldReturnStatusSetting = this.returnStatus;
this.returnStatus = true;
let environmentEditExitCode = 0;
process.env[variable] = value;
if(os.platform() === 'win32')
{
const setShellVariable = `set ${variable}=${value}`;
const setSystemVariable = `setx ${variable} "${value}"`;
await this.execute(setShellVariable);
await this.execute(setSystemVariable);
try
{
environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setShellVariable))[0]);
environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setSystemVariable))[0]);
}
catch(error)
{
if(failureWarningMessage)
{
new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, );
}
}
}
else
{
const setVariable = `${variable}=${value} && export ${variable}`
await this.execute(setVariable);
try
{
environmentEditExitCode = environmentEditExitCode || Number((await this.execute(setVariable))[0]);;
}
catch(error)
{
if(failureWarningMessage)
{
new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, );
}
}
}
if(environmentEditExitCode && failureWarningMessage)
{
new WindowDisplayWorker().showWarningMessage(failureWarningMessage, () => {/* No Callback */}, );
}
this.returnStatus = oldReturnStatusSetting;
}
}

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

@ -214,7 +214,6 @@ export class FileUtilities extends IFileUtilities
public async getFileHash(filePath : string) : Promise<string | null>
{
const res = await this.sha512Hasher(filePath);
return res;
}

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

@ -4,7 +4,7 @@
* ------------------------------------------------------------------------------------------ */
/* tslint:disable:no-any */
import { IEventStream } from "../EventStream/EventStream";
import { IEventStream } from '../EventStream/EventStream';
export abstract class IFileUtilities
{

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

@ -189,14 +189,14 @@ export class WebRequestWorker
return;
}
const finished = promisify(stream.finished);
const isFinished = promisify(stream.finished);
const file = fs.createWriteStream(dest, { flags: 'wx' });
const options = await this.getAxiosOptions(3, {responseType: 'stream', transformResponse: (x : any) => x}, false);
await this.axiosGet(url, options)
.then(response =>
{
response.data.pipe(file);
return finished(file);
return isFinished(file);
});
}

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

@ -295,9 +295,9 @@ export class MockFileUtilities extends IFileUtilities
{
private trueUtilities = new FileUtilities();
public writeFileOntoDisk(content : string, path : string)
public writeFileOntoDisk(content : string, filePath : string)
{
return this.trueUtilities.writeFileOntoDisk(content, path, new MockEventStream());
return this.trueUtilities.writeFileOntoDisk(content, filePath, new MockEventStream());
}
public wipeDirectory(directoryToWipe : string)

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

@ -56,7 +56,8 @@ suite('DotnetCoreAcquisitionWorker Unit Tests', function () {
installationValidator: new MockInstallationValidator(eventStream),
timeoutValue: 10,
installDirectoryProvider: runtimeInstall ? new RuntimeInstallationDirectoryProvider('') : new SdkInstallationDirectoryProvider(''),
installingArchitecture: arch
installingArchitecture: arch,
isExtensionTelemetryInitiallyEnabled: true
});
return [acquisitionWorker, eventStream, context];
}
@ -72,6 +73,7 @@ suite('DotnetCoreAcquisitionWorker Unit Tests', function () {
installationValidator: new MockInstallationValidator(eventStream),
timeoutValue: 10,
installDirectoryProvider: runtimeInstall ? new RuntimeInstallationDirectoryProvider('') : new SdkInstallationDirectoryProvider(''),
isExtensionTelemetryInitiallyEnabled: true
});
return [acquisitionWorker, eventStream, context];
}
@ -304,6 +306,7 @@ suite('DotnetCoreAcquisitionWorker Unit Tests', function () {
installationValidator: new MockInstallationValidator(eventStream),
timeoutValue: 10,
installDirectoryProvider: new RuntimeInstallationDirectoryProvider(''),
isExtensionTelemetryInitiallyEnabled: true
});
return assert.isRejected(acquisitionWorker.acquireRuntime('1.0'), '.NET Acquisition Failed: Installation failed: Rejecting message');

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

@ -21,6 +21,7 @@ export function getMockAcquiringContext(runtimeInstall: boolean, timeoutTime : n
installationValidator: new MockInstallationValidator(eventStream),
timeoutValue: timeoutTime,
installDirectoryProvider: runtimeInstall ? new RuntimeInstallationDirectoryProvider('') : new SdkInstallationDirectoryProvider(''),
isExtensionTelemetryInitiallyEnabled: true
};
return workerContext;
}

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

@ -51,6 +51,7 @@ suite('WebRequestWorker Unit Tests', () => {
installationValidator: new MockInstallationValidator(eventStream),
timeoutValue: 10,
installDirectoryProvider: new RuntimeInstallationDirectoryProvider(''),
isExtensionTelemetryInitiallyEnabled: true
});
return assert.isRejected(acquisitionWorker.acquireRuntime('1.0'), Error, '.NET Acquisition Failed');
});

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

@ -29,6 +29,7 @@ suite('Windows & Mac Global Installer Tests', () =>
installationValidator: new MockInstallationValidator(eventStream),
timeoutValue: standardTimeoutTime,
installDirectoryProvider: runtimeInstall ? new RuntimeInstallationDirectoryProvider('') : new SdkInstallationDirectoryProvider(''),
isExtensionTelemetryInitiallyEnabled: true,
};
return workerContext;
}

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

@ -74,11 +74,12 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE
extensionContext.extensionConfiguration :
vscode.workspace.getConfiguration(configPrefix);
const isExtensionTelemetryEnabled = enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry);
const eventStreamContext = {
displayChannelName,
logPath: context.logPath,
extensionId: dotnetCoreAcquisitionExtensionId,
enableTelemetry: enableExtensionTelemetry(extensionConfiguration, configKeys.enableTelemetry),
enableTelemetry: isExtensionTelemetryEnabled,
telemetryReporter: extensionContext ? extensionContext.telemetryReporter : undefined,
showLogCommand: `${commandPrefix}.${commandKeys.showAcquisitionLog}`,
packageJson,
@ -116,12 +117,6 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE
}
}
vscode.env.onDidChangeTelemetryEnabled((_: boolean) =>
{
console.log('foo');
});
const acquisitionWorker = new DotnetCoreAcquisitionWorker({
storagePath,
extensionState: context.globalState,
@ -130,7 +125,8 @@ export function activate(context: vscode.ExtensionContext, extensionContext?: IE
installationValidator: new InstallationValidator(eventStream),
timeoutValue: resolvedTimeoutSeconds,
installDirectoryProvider: new SdkInstallationDirectoryProvider(storagePath),
acquisitionContext : null
acquisitionContext : null,
isExtensionTelemetryInitiallyEnabled : isExtensionTelemetryEnabled
});
const versionResolver = new VersionResolver(context.globalState, eventStream, resolvedTimeoutSeconds);

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

@ -153,6 +153,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function()
installationValidator: new MockInstallationValidator(eventStream),
timeoutValue: 10,
installDirectoryProvider,
isExtensionTelemetryInitiallyEnabled: true
});
const version = currentSDKVersion;
@ -202,6 +203,7 @@ suite('DotnetCoreAcquisitionExtension End to End', function()
installationValidator: new MockInstallationValidator(eventStream),
timeoutValue: 10,
installDirectoryProvider,
isExtensionTelemetryInitiallyEnabled: true,
});
const version = currentSDKVersion;