mirror of
https://github.com/Microsoft/vscode
synced 2024-08-25 03:56:03 +00:00
maintain promise instead in github-auth to ensure the exp service doesn't get created twice
This commit is contained in:
parent
437f5b7559
commit
8a4ace6ebf
|
@ -9,17 +9,40 @@ import { getExperimentationService, IExperimentationService, IExperimentationTel
|
|||
|
||||
export class ExperimentationTelemetry implements IExperimentationTelemetry {
|
||||
private sharedProperties: Record<string, string> = {};
|
||||
private experimentationService: IExperimentationService | undefined;
|
||||
private experimentationServicePromise: Promise<IExperimentationService> | undefined;
|
||||
|
||||
constructor(private readonly context: vscode.ExtensionContext, private baseReporter: TelemetryReporter) { }
|
||||
|
||||
private async createExperimentationService(): Promise<IExperimentationService> {
|
||||
let targetPopulation: TargetPopulation;
|
||||
switch (vscode.env.uriScheme) {
|
||||
case 'vscode':
|
||||
targetPopulation = TargetPopulation.Public;
|
||||
case 'vscode-insiders':
|
||||
targetPopulation = TargetPopulation.Insiders;
|
||||
case 'vscode-exploration':
|
||||
targetPopulation = TargetPopulation.Internal;
|
||||
case 'code-oss':
|
||||
targetPopulation = TargetPopulation.Team;
|
||||
default:
|
||||
targetPopulation = TargetPopulation.Public;
|
||||
}
|
||||
|
||||
const id = this.context.extension.id;
|
||||
const version = this.context.extension.packageJSON.version;
|
||||
const experimentationService = getExperimentationService(id, version, targetPopulation, this, this.context.globalState);
|
||||
await experimentationService.initialFetch;
|
||||
return experimentationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns A promise that you shouldn't need to await because this is just telemetry.
|
||||
*/
|
||||
async sendTelemetryEvent(eventName: string, properties?: Record<string, string>, measurements?: Record<string, number>) {
|
||||
if (!this.experimentationService) {
|
||||
this.experimentationService = await createExperimentationService(this.context, this);
|
||||
if (!this.experimentationServicePromise) {
|
||||
this.experimentationServicePromise = this.createExperimentationService();
|
||||
}
|
||||
await this.experimentationServicePromise;
|
||||
|
||||
this.baseReporter.sendTelemetryEvent(
|
||||
eventName,
|
||||
|
@ -39,9 +62,10 @@ export class ExperimentationTelemetry implements IExperimentationTelemetry {
|
|||
properties?: Record<string, string>,
|
||||
_measurements?: Record<string, number>
|
||||
) {
|
||||
if (!this.experimentationService) {
|
||||
this.experimentationService = await createExperimentationService(this.context, this);
|
||||
if (!this.experimentationServicePromise) {
|
||||
this.experimentationServicePromise = this.createExperimentationService();
|
||||
}
|
||||
await this.experimentationServicePromise;
|
||||
|
||||
this.baseReporter.sendTelemetryErrorEvent(eventName, {
|
||||
...this.sharedProperties,
|
||||
|
@ -65,26 +89,3 @@ export class ExperimentationTelemetry implements IExperimentationTelemetry {
|
|||
return this.baseReporter.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
function getTargetPopulation(): TargetPopulation {
|
||||
switch (vscode.env.uriScheme) {
|
||||
case 'vscode':
|
||||
return TargetPopulation.Public;
|
||||
case 'vscode-insiders':
|
||||
return TargetPopulation.Insiders;
|
||||
case 'vscode-exploration':
|
||||
return TargetPopulation.Internal;
|
||||
case 'code-oss':
|
||||
return TargetPopulation.Team;
|
||||
default:
|
||||
return TargetPopulation.Public;
|
||||
}
|
||||
}
|
||||
|
||||
async function createExperimentationService(context: vscode.ExtensionContext, telemetry: ExperimentationTelemetry): Promise<IExperimentationService> {
|
||||
const id = context.extension.id;
|
||||
const version = context.extension.packageJSON.version;
|
||||
const experimentationService = getExperimentationService(id, version, getTargetPopulation(), telemetry, context.globalState);
|
||||
await experimentationService.initialFetch;
|
||||
return experimentationService;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue