Skip to content

Commit

Permalink
Revert "remove exp telemetry & stable v2 (#76)"
Browse files Browse the repository at this point in the history
This reverts commit add9e26.
  • Loading branch information
zhiyuanliang-ms committed Jan 8, 2025
1 parent f247557 commit aa7c4fe
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/feature-management-applicationinsights-browser",
"version": "2.0.0",
"version": "2.0.0-preview.3",
"description": "Feature Management Application Insights Plugin for Browser provides a solution for sending feature flag evaluation events produced by the Feature Management library.",
"main": "./dist/umd/index.js",
"module": "./dist/esm/index.js",
Expand All @@ -24,9 +24,6 @@
"url": "git+https://github.com/microsoft/FeatureManagement-JavaScript.git"
},
"license": "MIT",
"publishConfig": {
"tag": "stable"
},
"bugs": {
"url": "https://github.com/microsoft/FeatureManagement-JavaScript/issues"
},
Expand All @@ -45,7 +42,7 @@
},
"dependencies": {
"@microsoft/applicationinsights-web": "^3.3.2",
"@microsoft/feature-management": "2.0.0"
"@microsoft/feature-management": "2.0.0-preview.3"
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const VERSION = "2.0.0";
export const VERSION = "2.0.0-preview.3";
7 changes: 2 additions & 5 deletions sdk/feature-management-applicationinsights-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/feature-management-applicationinsights-node",
"version": "2.0.0",
"version": "2.0.0-preview.3",
"description": "Feature Management Application Insights Plugin for Node.js provides a solution for sending feature flag evaluation events produced by the Feature Management library.",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js",
Expand All @@ -24,9 +24,6 @@
"url": "git+https://github.com/microsoft/FeatureManagement-JavaScript.git"
},
"license": "MIT",
"publishConfig": {
"tag": "stable"
},
"bugs": {
"url": "https://github.com/microsoft/FeatureManagement-JavaScript/issues"
},
Expand All @@ -45,7 +42,7 @@
},
"dependencies": {
"applicationinsights": "^2.9.6",
"@microsoft/feature-management": "2.0.0"
"@microsoft/feature-management": "2.0.0-preview.3"
}
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const VERSION = "2.0.0";
export const VERSION = "2.0.0-preview.3";
2 changes: 1 addition & 1 deletion sdk/feature-management/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions sdk/feature-management/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft/feature-management",
"version": "2.0.0",
"version": "2.0.0-preview.3",
"description": "Feature Management is a library for enabling/disabling features at runtime. Developers can use feature flags in simple use cases like conditional statement to more advanced scenarios like conditionally adding routes.",
"main": "./dist/commonjs/index.js",
"module": "./dist/esm/index.js",
Expand All @@ -26,9 +26,6 @@
"url": "git+https://github.com/microsoft/FeatureManagement-JavaScript.git"
},
"license": "MIT",
"publishConfig": {
"tag": "stable"
},
"bugs": {
"url": "https://github.com/microsoft/FeatureManagement-JavaScript/issues"
},
Expand Down
29 changes: 28 additions & 1 deletion sdk/feature-management/src/telemetry/featureEvaluationEvent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { EvaluationResult } from "../featureManager";
import { EvaluationResult, VariantAssignmentReason } from "../featureManager";
import { EVALUATION_EVENT_VERSION } from "../version.js";

const VERSION = "Version";
Expand All @@ -10,6 +10,8 @@ const ENABLED = "Enabled";
const TARGETING_ID = "TargetingId";
const VARIANT = "Variant";
const VARIANT_ASSIGNMENT_REASON = "VariantAssignmentReason";
const DEFAULT_WHEN_ENABLED = "DefaultWhenEnabled";
const VARIANT_ASSIGNMENT_PERCENTAGE = "VariantAssignmentPercentage";

export function createFeatureEvaluationEventProperties(result: EvaluationResult): any {
if (result.feature === undefined) {
Expand All @@ -26,6 +28,31 @@ export function createFeatureEvaluationEventProperties(result: EvaluationResult)
[VARIANT_ASSIGNMENT_REASON]: result.variantAssignmentReason,
};

if (result.feature.allocation?.default_when_enabled) {
eventProperties[DEFAULT_WHEN_ENABLED] = result.feature.allocation.default_when_enabled;
}

if (result.variantAssignmentReason === VariantAssignmentReason.DefaultWhenEnabled) {
let percentileAllocationPercentage = 0;
if (result.variant !== undefined && result.feature.allocation !== undefined && result.feature.allocation.percentile !== undefined) {
for (const percentile of result.feature.allocation.percentile) {
percentileAllocationPercentage += percentile.to - percentile.from;
}
}
eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = (100 - percentileAllocationPercentage).toString();
}
else if (result.variantAssignmentReason === VariantAssignmentReason.Percentile) {
let percentileAllocationPercentage = 0;
if (result.variant !== undefined && result.feature.allocation !== undefined && result.feature.allocation.percentile !== undefined) {
for (const percentile of result.feature.allocation.percentile) {
if (percentile.variant === result.variant.name) {
percentileAllocationPercentage += percentile.to - percentile.from;
}
}
}
eventProperties[VARIANT_ASSIGNMENT_PERCENTAGE] = percentileAllocationPercentage.toString();
}

const metadata = result.feature.telemetry?.metadata;
if (metadata) {
for (const key in metadata) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/feature-management/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export const VERSION = "2.0.0";
export const VERSION = "2.0.0-preview.3";
export const EVALUATION_EVENT_VERSION = "1.0.0";

0 comments on commit aa7c4fe

Please sign in to comment.