Add experimentation to Microsoft auth (#226107)

* Add experimentation to Microsoft auth

So that we can gradually roll out MSAL support.

* correct order
This commit is contained in:
Tyler James Leonhardt
2024-08-20 17:17:15 -07:00
committed by GitHub
parent b8ad412410
commit c125b90d41
7 changed files with 101 additions and 15 deletions

View File

@@ -0,0 +1,26 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import { getExperimentationService, IExperimentationService, IExperimentationTelemetry, TargetPopulation } from 'vscode-tas-client';
export async function createExperimentationService(
context: vscode.ExtensionContext,
experimentationTelemetry: IExperimentationTelemetry,
isPreRelease: boolean,
): Promise<IExperimentationService> {
const id = context.extension.id;
const version = context.extension.packageJSON['version'];
const service = getExperimentationService(
id,
version,
isPreRelease ? TargetPopulation.Insiders : TargetPopulation.Public,
experimentationTelemetry,
context.globalState,
) as unknown as IExperimentationService;
await service.initializePromise;
await service.initialFetch;
return service;
}

View File

@@ -3,7 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import TelemetryReporter from '@vscode/extension-telemetry';
import TelemetryReporter, { TelemetryEventProperties } from '@vscode/extension-telemetry';
import { IExperimentationTelemetry } from 'vscode-tas-client';
export const enum MicrosoftAccountType {
AAD = 'aad',
@@ -11,12 +12,29 @@ export const enum MicrosoftAccountType {
Unknown = 'unknown'
}
export class MicrosoftAuthenticationTelemetryReporter {
export class MicrosoftAuthenticationTelemetryReporter implements IExperimentationTelemetry {
private sharedProperties: Record<string, string> = {};
protected _telemetryReporter: TelemetryReporter;
constructor(aiKey: string) {
this._telemetryReporter = new TelemetryReporter(aiKey);
}
get telemetryReporter(): TelemetryReporter {
return this._telemetryReporter;
}
setSharedProperty(name: string, value: string): void {
this.sharedProperties[name] = value;
}
postEvent(eventName: string, props: Map<string, string>): void {
const eventProperties: TelemetryEventProperties = { ...this.sharedProperties, ...Object.fromEntries(props) };
this._telemetryReporter.sendTelemetryEvent(
eventName,
eventProperties
);
}
sendLoginEvent(scopes: readonly string[]): void {
/* __GDPR__
"login" : {