Skip to content

Commit f04b8bd

Browse files
update
1 parent e9a00c4 commit f04b8bd

File tree

9 files changed

+69
-99
lines changed

9 files changed

+69
-99
lines changed

sdk/feature-management-applicationinsights-browser/.eslintrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"env": {
33
"browser": true,
4-
"commonjs": true,
54
"es2021": true,
6-
"node": true,
75
"mocha": true
86
},
97
"extends": [

sdk/feature-management-applicationinsights-browser/src/telemetry.ts

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,26 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { EvaluationResult, VariantAssignmentReason } from "@microsoft/feature-management";
4+
import { EvaluationResult, createFeatureEvaluationEventProperties } from "@microsoft/feature-management";
55
import { ApplicationInsights, IEventTelemetry } from "@microsoft/applicationinsights-web";
6-
import { EVALUATION_EVENT_VERSION } from "./version.js";
76

8-
const VERSION = "Version";
9-
const FEATURE_NAME = "FeatureName";
10-
const ENABLED = "Enabled";
117
const TARGETING_ID = "TargetingId";
12-
const VARIANT = "Variant";
13-
const VARIANT_ASSIGNMENT_REASON = "VariantAssignmentReason";
14-
const DEFAULT_WHEN_ENABLED = "DefaultWhenEnabled";
15-
const VARIANT_ASSIGNMENT_PERCENTAGE = "VariantAssignmentPercentage";
168
const FEATURE_EVALUATION_EVENT_NAME = "FeatureEvaluation";
179

1810
/**
1911
* Creates a telemetry publisher that sends feature evaluation events to Application Insights.
2012
* @param client The Application Insights telemetry client.
2113
* @returns A callback function that takes an evaluation result and tracks an event with the evaluation details.
2214
*/
23-
export function createTelemetryPublisher(client: ApplicationInsights): (event: EvaluationResult) => void {
24-
return (event: EvaluationResult) => {
25-
if (event.feature === undefined) {
15+
export function createTelemetryPublisher(client: ApplicationInsights): (result: EvaluationResult) => void {
16+
return (result: EvaluationResult) => {
17+
if (result.feature === undefined) {
2618
return;
2719
}
2820

29-
const eventProperties = {
30-
[VERSION]: EVALUATION_EVENT_VERSION,
31-
[FEATURE_NAME]: event.feature ? event.feature.id : "",
32-
[ENABLED]: event.enabled.toString(),
33-
// Ensure targetingId is string so that it will be placed in customDimensions
34-
[TARGETING_ID]: event.targetingId ? event.targetingId.toString() : "",
35-
[VARIANT]: event.variant ? event.variant.name : "",
36-
[VARIANT_ASSIGNMENT_REASON]: event.variantAssignmentReason,
37-
};
21+
const eventProperties = createFeatureEvaluationEventProperties(result);
3822

39-
if (event.feature.allocation?.default_when_enabled) {
40-
eventProperties[DEFAULT_WHEN_ENABLED] = event.feature.allocation.default_when_enabled;
41-
}
42-
43-
if (event.variantAssignmentReason === VariantAssignmentReason.DefaultWhenEnabled) {
44-
let percentileAllocationPercentage = 0;
45-
if (event.variant !== undefined && event.feature.allocation !== undefined && event.feature.allocation.percentile !== undefined) {
46-
for (const percentile of event.feature.allocation.percentile) {
47-
percentileAllocationPercentage += percentile.to - percentile.from;
48-
}
49-
}
50-
eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = (100 - percentileAllocationPercentage).toString();
51-
}
52-
else if (event.variantAssignmentReason === VariantAssignmentReason.Percentile) {
53-
let percentileAllocationPercentage = 0;
54-
if (event.variant !== undefined && event.feature.allocation !== undefined && event.feature.allocation.percentile !== undefined) {
55-
for (const percentile of event.feature.allocation.percentile) {
56-
if (percentile.variant === event.variant.name) {
57-
percentileAllocationPercentage += percentile.to - percentile.from;
58-
}
59-
}
60-
}
61-
eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = percentileAllocationPercentage.toString();
62-
}
63-
64-
const metadata = event.feature.telemetry?.metadata;
23+
const metadata = result.feature.telemetry?.metadata;
6524
if (metadata) {
6625
for (const key in metadata) {
6726
if (!(key in eventProperties)) {

sdk/feature-management-applicationinsights-browser/src/version.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
// Licensed under the MIT license.
33

44
export const VERSION = "2.0.0-preview.2";
5-
export const EVALUATION_EVENT_VERSION = "1.0.0";

sdk/feature-management-applicationinsights-node/.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"env": {
3-
"browser": true,
43
"commonjs": true,
54
"es2021": true,
65
"node": true,

sdk/feature-management-applicationinsights-node/src/telemetry.ts

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,26 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4-
import { EvaluationResult, VariantAssignmentReason } from "@microsoft/feature-management";
4+
import { EvaluationResult, createFeatureEvaluationEventProperties } from "@microsoft/feature-management";
55
import { TelemetryClient, Contracts } from "applicationinsights";
6-
import { EVALUATION_EVENT_VERSION } from "./version.js";
76

8-
const VERSION = "Version";
9-
const FEATURE_NAME = "FeatureName";
10-
const ENABLED = "Enabled";
117
const TARGETING_ID = "TargetingId";
12-
const VARIANT = "Variant";
13-
const VARIANT_ASSIGNMENT_REASON = "VariantAssignmentReason";
14-
const DEFAULT_WHEN_ENABLED = "DefaultWhenEnabled";
15-
const VARIANT_ASSIGNMENT_PERCENTAGE = "VariantAssignmentPercentage";
168
const FEATURE_EVALUATION_EVENT_NAME = "FeatureEvaluation";
179

1810
/**
1911
* Creates a telemetry publisher that sends feature evaluation events to Application Insights.
2012
* @param client The Application Insights telemetry client.
2113
* @returns A callback function that takes an evaluation result and tracks an event with the evaluation details.
2214
*/
23-
export function createTelemetryPublisher(client: TelemetryClient): (event: EvaluationResult) => void {
24-
return (event: EvaluationResult) => {
25-
if (event.feature === undefined) {
15+
export function createTelemetryPublisher(client: TelemetryClient): (result: EvaluationResult) => void {
16+
return (result: EvaluationResult) => {
17+
if (result.feature === undefined) {
2618
return;
2719
}
2820

29-
const eventProperties = {
30-
[VERSION]: EVALUATION_EVENT_VERSION,
31-
[FEATURE_NAME]: event.feature ? event.feature.id : "",
32-
[ENABLED]: event.enabled.toString(),
33-
// Ensure targetingId is string so that it will be placed in customDimensions
34-
[TARGETING_ID]: event.targetingId ? event.targetingId.toString() : "",
35-
[VARIANT]: event.variant ? event.variant.name : "",
36-
[VARIANT_ASSIGNMENT_REASON]: event.variantAssignmentReason,
37-
};
21+
const eventProperties = createFeatureEvaluationEventProperties(result);
3822

39-
if (event.feature.allocation?.default_when_enabled) {
40-
eventProperties[DEFAULT_WHEN_ENABLED] = event.feature.allocation.default_when_enabled;
41-
}
42-
43-
if (event.variantAssignmentReason === VariantAssignmentReason.DefaultWhenEnabled) {
44-
let percentileAllocationPercentage = 0;
45-
if (event.variant !== undefined && event.feature.allocation !== undefined && event.feature.allocation.percentile !== undefined) {
46-
for (const percentile of event.feature.allocation.percentile) {
47-
percentileAllocationPercentage += percentile.to - percentile.from;
48-
}
49-
}
50-
eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = (100 - percentileAllocationPercentage).toString();
51-
}
52-
else if (event.variantAssignmentReason === VariantAssignmentReason.Percentile) {
53-
let percentileAllocationPercentage = 0;
54-
if (event.variant !== undefined && event.feature.allocation !== undefined && event.feature.allocation.percentile !== undefined) {
55-
for (const percentile of event.feature.allocation.percentile) {
56-
if (percentile.variant === event.variant.name) {
57-
percentileAllocationPercentage += percentile.to - percentile.from;
58-
}
59-
}
60-
}
61-
eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = percentileAllocationPercentage.toString();
62-
}
63-
64-
const metadata = event.feature.telemetry?.metadata;
23+
const metadata = result.feature.telemetry?.metadata;
6524
if (metadata) {
6625
for (const key in metadata) {
6726
if (!(key in eventProperties)) {

sdk/feature-management-applicationinsights-node/src/version.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
// Licensed under the MIT license.
33

44
export const VERSION = "2.0.0-preview.2";
5-
export const EVALUATION_EVENT_VERSION = "1.0.0";

sdk/feature-management/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33

44
export { FeatureManager, FeatureManagerOptions, EvaluationResult, VariantAssignmentReason } from "./featureManager.js";
55
export { ConfigurationMapFeatureFlagProvider, ConfigurationObjectFeatureFlagProvider, IFeatureFlagProvider } from "./featureProvider.js";
6+
export { createFeatureEvaluationEventProperties } from "./telemetry/featureEvaluationEvent.js";
67
export { IFeatureFilter } from "./filter/FeatureFilter.js";
78
export { VERSION } from "./version.js";
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
import { EvaluationResult, VariantAssignmentReason } from "../featureManager";
5+
import { EVALUATION_EVENT_VERSION } from "../version.js";
6+
7+
const VERSION = "Version";
8+
const FEATURE_NAME = "FeatureName";
9+
const ENABLED = "Enabled";
10+
const TARGETING_ID = "TargetingId";
11+
const VARIANT = "Variant";
12+
const VARIANT_ASSIGNMENT_REASON = "VariantAssignmentReason";
13+
const DEFAULT_WHEN_ENABLED = "DefaultWhenEnabled";
14+
const VARIANT_ASSIGNMENT_PERCENTAGE = "VariantAssignmentPercentage";
15+
16+
export function createFeatureEvaluationEventProperties(result: EvaluationResult): any {
17+
if (result.feature === undefined) {
18+
return undefined;
19+
}
20+
21+
const eventProperties = {
22+
[VERSION]: EVALUATION_EVENT_VERSION,
23+
[FEATURE_NAME]: result.feature ? result.feature.id : "",
24+
[ENABLED]: result.enabled.toString(),
25+
// Ensure targetingId is string so that it will be placed in customDimensions
26+
[TARGETING_ID]: result.targetingId ? result.targetingId.toString() : "",
27+
[VARIANT]: result.variant ? result.variant.name : "",
28+
[VARIANT_ASSIGNMENT_REASON]: result.variantAssignmentReason,
29+
};
30+
31+
if (result.feature.allocation?.default_when_enabled) {
32+
eventProperties[DEFAULT_WHEN_ENABLED] = result.feature.allocation.default_when_enabled;
33+
}
34+
35+
if (result.variantAssignmentReason === VariantAssignmentReason.DefaultWhenEnabled) {
36+
let percentileAllocationPercentage = 0;
37+
if (result.variant !== undefined && result.feature.allocation !== undefined && result.feature.allocation.percentile !== undefined) {
38+
for (const percentile of result.feature.allocation.percentile) {
39+
percentileAllocationPercentage += percentile.to - percentile.from;
40+
}
41+
}
42+
eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = (100 - percentileAllocationPercentage).toString();
43+
}
44+
else if (result.variantAssignmentReason === VariantAssignmentReason.Percentile) {
45+
let percentileAllocationPercentage = 0;
46+
if (result.variant !== undefined && result.feature.allocation !== undefined && result.feature.allocation.percentile !== undefined) {
47+
for (const percentile of result.feature.allocation.percentile) {
48+
if (percentile.variant === result.variant.name) {
49+
percentileAllocationPercentage += percentile.to - percentile.from;
50+
}
51+
}
52+
}
53+
eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = percentileAllocationPercentage.toString();
54+
}
55+
}

sdk/feature-management/src/version.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
// Licensed under the MIT license.
33

44
export const VERSION = "2.0.0-preview.2";
5+
export const EVALUATION_EVENT_VERSION = "1.0.0";

0 commit comments

Comments
 (0)