Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions tas-client/src/tas-client/ExperimentationServiceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ export abstract class ExperimentationServiceBase implements IExperimentationServ
*/
public isFlightEnabled(flight: string): boolean {
this.featuresConsumed = true;
this.PostEventToTelemetry(flight);
return this.features.features.includes(flight);
const isEnabled = this.features.features.includes(flight);
this.PostEventToTelemetry(flight, isEnabled);
return isEnabled;
}

/**
Expand All @@ -200,8 +201,9 @@ export abstract class ExperimentationServiceBase implements IExperimentationServ
public async isCachedFlightEnabled(flight: string): Promise<boolean> {
await this.loadCachePromise;
this.featuresConsumed = true;
this.PostEventToTelemetry(flight);
return this.features.features.includes(flight);
const isEnabled = this.features.features.includes(flight);
this.PostEventToTelemetry(flight, isEnabled);
return isEnabled;
}

/**
Expand All @@ -212,8 +214,9 @@ export abstract class ExperimentationServiceBase implements IExperimentationServ
public async isFlightEnabledAsync(flight: string): Promise<boolean> {
const features = await this.getFeaturesAsync(true);
this.featuresConsumed = true;
this.PostEventToTelemetry(flight);
return features.features.includes(flight);
const isEnabled = features.features.includes(flight);
this.PostEventToTelemetry(flight, isEnabled);
return isEnabled;
}

/**
Expand All @@ -225,9 +228,10 @@ export abstract class ExperimentationServiceBase implements IExperimentationServ
*/
public getTreatmentVariable<T extends boolean | number | string>(configId: string, name: string): T | undefined {
this.featuresConsumed = true;
this.PostEventToTelemetry(`${configId}.${name}`);
const config = this.features.configs.find(c => c.Id === configId);
return config?.Parameters[name] as T;
const value = config?.Parameters[name] as T;
this.PostEventToTelemetry(`${configId}.${name}`, value);
return value;
}

/**
Expand All @@ -252,16 +256,22 @@ export abstract class ExperimentationServiceBase implements IExperimentationServ
return this.getTreatmentVariable<T>(configId, name);
}

private PostEventToTelemetry(flight: string): void {
private PostEventToTelemetry(flight: string, featureValue?: boolean | number | string): void {
/**
* If this event has already been posted, we omit from posting it again.
*/
if (this.cachedTelemetryEvents.includes(flight)) {
return;
}

const telemetryProperties = new Map<string, string>([['ABExp.queriedFeature', flight]]);
if (featureValue !== undefined) {
telemetryProperties.set('abexp.featurevalue', String(featureValue));
}

this.telemetry.postEvent(
this.telemetryEventName,
new Map<string, string>([['ABExp.queriedFeature', flight]]),
telemetryProperties,
);

/**
Expand Down