@microsoft/feature-management-applicationinsights-browser 2.0.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Microsoft Feature Management Application Insights Plugin for Browser
2
+
3
+ Feature Management Application Insights Plugin for Browser provides a solution for sending feature flag evaluation events produced by the Feature Management library.
4
+
5
+ ## Getting Started
6
+
7
+ ### Prerequisites
8
+
9
+ - Node.js LTS version
10
+
11
+ ### Usage
12
+
13
+ ``` javascript
14
+ import { ApplicationInsights } from "@microsoft/applicationinsights-web"
15
+ import { FeatureManager, ConfigurationObjectFeatureFlagProvider } from "@microsoft/feature-management";
16
+ import { trackEvent, createTelemetryPublisher } from "@microsoft/feature-management-applicationinsights-browser";
17
+
18
+ const appInsights = new ApplicationInsights({ config: {
19
+ connectionString: CONNECTION_STRING
20
+ }});
21
+ appInsights.loadAppInsights();
22
+
23
+ const publishTelemetry = createTelemetryPublisher(appInsights);
24
+ const provider = new ConfigurationObjectFeatureFlagProvider(jsonObject);
25
+ const featureManager = new FeatureManager(provider, {onFeatureEvaluated: publishTelemetry});
26
+
27
+ // FeatureEvaluation event will be emitted when a feature flag is evaluated
28
+ featureManager.getVariant("TestFeature", {userId : TARGETING_ID}).then((variant) => { /* do something*/ });
29
+
30
+ // Emit a custom event with targeting id attached.
31
+ trackEvent(appInsights, TARGETING_ID, {name: "TestEvent"}, {"Tag": "Some Value"});
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
37
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
38
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
39
+
40
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
41
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
42
+ provided by the bot. You will only need to do this once across all repos using our CLA.
43
+
44
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
45
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
46
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
47
+
48
+ ## Trademarks
49
+
50
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
51
+ trademarks or logos is subject to and must follow
52
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
53
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
54
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
@@ -0,0 +1,3 @@
1
+ export { createTelemetryPublisher, trackEvent } from './telemetry.js';
2
+ export { VERSION } from './version.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,47 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ /**
4
+ * Creates a telemetry publisher that sends feature evaluation events to Application Insights.
5
+ * @param client The Application Insights telemetry client.
6
+ * @returns A callback function that takes an evaluation result and tracks an event with the evaluation details.
7
+ */
8
+ function createTelemetryPublisher(client) {
9
+ return (event) => {
10
+ const eventProperties = {
11
+ "FeatureName": event.feature?.id,
12
+ "Enabled": event.enabled.toString(),
13
+ // Ensure targetingId is string so that it will be placed in customDimensions
14
+ "TargetingId": event.targetingId?.toString(),
15
+ "Variant": event.variant?.name,
16
+ "VariantAssignmentReason": event.variantAssignmentReason,
17
+ };
18
+ const metadata = event.feature?.telemetry?.metadata;
19
+ if (metadata) {
20
+ for (const key in metadata) {
21
+ if (!(key in eventProperties)) {
22
+ eventProperties[key] = metadata[key];
23
+ }
24
+ }
25
+ }
26
+ client.trackEvent({ name: "FeatureEvaluation" }, eventProperties);
27
+ };
28
+ }
29
+ /**
30
+ * Tracks a custom event using Application Insights, ensuring that the "TargetingId"
31
+ * is included in the custom properties. If the "TargetingId" already exists in
32
+ * the provided custom properties, it will be overwritten.
33
+ *
34
+ * @param client The Application Insights client instance used to track the event.
35
+ * @param targetingId The unique targeting identifier that will be included in the custom properties.
36
+ * @param event The event telemetry object to be tracked, containing event details.
37
+ * @param customProperties (Optional) Additional properties to include in the event telemetry.
38
+ */
39
+ function trackEvent(client, targetingId, event, customProperties) {
40
+ const properties = customProperties ? { ...customProperties } : {};
41
+ // Ensure targetingId is string so that it will be placed in customDimensions
42
+ properties["TargetingId"] = targetingId?.toString();
43
+ client.trackEvent(event, properties);
44
+ }
45
+
46
+ export { createTelemetryPublisher, trackEvent };
47
+ //# sourceMappingURL=telemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.js","sources":["../../src/telemetry.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { EvaluationResult } from \"@microsoft/feature-management\";\nimport { ApplicationInsights } from \"@microsoft/applicationinsights-web\";\nimport { IEventTelemetry } from \"@microsoft/applicationinsights-web\";\n\n/**\n * Creates a telemetry publisher that sends feature evaluation events to Application Insights.\n * @param client The Application Insights telemetry client.\n * @returns A callback function that takes an evaluation result and tracks an event with the evaluation details.\n */\nexport function createTelemetryPublisher(client: ApplicationInsights): (event: EvaluationResult) => void {\n return (event: EvaluationResult) => {\n const eventProperties = {\n \"FeatureName\": event.feature?.id,\n \"Enabled\": event.enabled.toString(),\n // Ensure targetingId is string so that it will be placed in customDimensions\n \"TargetingId\": event.targetingId?.toString(),\n \"Variant\": event.variant?.name,\n \"VariantAssignmentReason\": event.variantAssignmentReason,\n };\n\n const metadata = event.feature?.telemetry?.metadata;\n if (metadata) {\n for (const key in metadata) {\n if (!(key in eventProperties)) {\n eventProperties[key] = metadata[key];\n }\n }\n }\n\n client.trackEvent({ name: \"FeatureEvaluation\" }, eventProperties);\n };\n}\n\n/**\n * Tracks a custom event using Application Insights, ensuring that the \"TargetingId\"\n * is included in the custom properties. If the \"TargetingId\" already exists in\n * the provided custom properties, it will be overwritten.\n *\n * @param client The Application Insights client instance used to track the event.\n * @param targetingId The unique targeting identifier that will be included in the custom properties.\n * @param event The event telemetry object to be tracked, containing event details.\n * @param customProperties (Optional) Additional properties to include in the event telemetry.\n */\nexport function trackEvent(client: ApplicationInsights, targetingId: string, event: IEventTelemetry, customProperties?: {[key: string]: any}): void {\n const properties = customProperties ? { ...customProperties } : {};\n // Ensure targetingId is string so that it will be placed in customDimensions\n properties[\"TargetingId\"] = targetingId?.toString();\n client.trackEvent(event, properties);\n}\n"],"names":[],"mappings":"AAAA;AACA;AAMA;;;;AAIG;AACG,SAAU,wBAAwB,CAAC,MAA2B,EAAA;IAChE,OAAO,CAAC,KAAuB,KAAI;AAC/B,QAAA,MAAM,eAAe,GAAG;AACpB,YAAA,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE;AAChC,YAAA,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE;;AAEnC,YAAA,aAAa,EAAE,KAAK,CAAC,WAAW,EAAE,QAAQ,EAAE;AAC5C,YAAA,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI;YAC9B,yBAAyB,EAAE,KAAK,CAAC,uBAAuB;SAC3D,CAAC;QAEF,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;QACpD,IAAI,QAAQ,EAAE;AACV,YAAA,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;AACxB,gBAAA,IAAI,EAAE,GAAG,IAAI,eAAe,CAAC,EAAE;oBAC3B,eAAe,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;iBACxC;aACJ;SACJ;QAED,MAAM,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,eAAe,CAAC,CAAC;AACtE,KAAC,CAAC;AACN,CAAC;AAED;;;;;;;;;AASG;AACG,SAAU,UAAU,CAAC,MAA2B,EAAE,WAAmB,EAAE,KAAsB,EAAE,gBAAuC,EAAA;AACxI,IAAA,MAAM,UAAU,GAAG,gBAAgB,GAAG,EAAE,GAAG,gBAAgB,EAAE,GAAG,EAAE,CAAC;;IAEnE,UAAU,CAAC,aAAa,CAAC,GAAG,WAAW,EAAE,QAAQ,EAAE,CAAC;AACpD,IAAA,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;AACzC;;;;"}
@@ -0,0 +1,6 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ const VERSION = "2.0.0-preview.1";
4
+
5
+ export { VERSION };
6
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sources":["../../src/version.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const VERSION = \"2.0.0-preview.1\";\n"],"names":[],"mappings":"AAAA;AACA;AAEO,MAAM,OAAO,GAAG;;;;"}
@@ -0,0 +1,61 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.FeatureManagementApplicationInsights = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ // Copyright (c) Microsoft Corporation.
8
+ // Licensed under the MIT license.
9
+ /**
10
+ * Creates a telemetry publisher that sends feature evaluation events to Application Insights.
11
+ * @param client The Application Insights telemetry client.
12
+ * @returns A callback function that takes an evaluation result and tracks an event with the evaluation details.
13
+ */
14
+ function createTelemetryPublisher(client) {
15
+ return (event) => {
16
+ const eventProperties = {
17
+ "FeatureName": event.feature?.id,
18
+ "Enabled": event.enabled.toString(),
19
+ // Ensure targetingId is string so that it will be placed in customDimensions
20
+ "TargetingId": event.targetingId?.toString(),
21
+ "Variant": event.variant?.name,
22
+ "VariantAssignmentReason": event.variantAssignmentReason,
23
+ };
24
+ const metadata = event.feature?.telemetry?.metadata;
25
+ if (metadata) {
26
+ for (const key in metadata) {
27
+ if (!(key in eventProperties)) {
28
+ eventProperties[key] = metadata[key];
29
+ }
30
+ }
31
+ }
32
+ client.trackEvent({ name: "FeatureEvaluation" }, eventProperties);
33
+ };
34
+ }
35
+ /**
36
+ * Tracks a custom event using Application Insights, ensuring that the "TargetingId"
37
+ * is included in the custom properties. If the "TargetingId" already exists in
38
+ * the provided custom properties, it will be overwritten.
39
+ *
40
+ * @param client The Application Insights client instance used to track the event.
41
+ * @param targetingId The unique targeting identifier that will be included in the custom properties.
42
+ * @param event The event telemetry object to be tracked, containing event details.
43
+ * @param customProperties (Optional) Additional properties to include in the event telemetry.
44
+ */
45
+ function trackEvent(client, targetingId, event, customProperties) {
46
+ const properties = customProperties ? { ...customProperties } : {};
47
+ // Ensure targetingId is string so that it will be placed in customDimensions
48
+ properties["TargetingId"] = targetingId?.toString();
49
+ client.trackEvent(event, properties);
50
+ }
51
+
52
+ // Copyright (c) Microsoft Corporation.
53
+ // Licensed under the MIT license.
54
+ const VERSION = "2.0.0-preview.1";
55
+
56
+ exports.VERSION = VERSION;
57
+ exports.createTelemetryPublisher = createTelemetryPublisher;
58
+ exports.trackEvent = trackEvent;
59
+
60
+ }));
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/telemetry.ts","../../src/version.ts"],"sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { EvaluationResult } from \"@microsoft/feature-management\";\nimport { ApplicationInsights } from \"@microsoft/applicationinsights-web\";\nimport { IEventTelemetry } from \"@microsoft/applicationinsights-web\";\n\n/**\n * Creates a telemetry publisher that sends feature evaluation events to Application Insights.\n * @param client The Application Insights telemetry client.\n * @returns A callback function that takes an evaluation result and tracks an event with the evaluation details.\n */\nexport function createTelemetryPublisher(client: ApplicationInsights): (event: EvaluationResult) => void {\n return (event: EvaluationResult) => {\n const eventProperties = {\n \"FeatureName\": event.feature?.id,\n \"Enabled\": event.enabled.toString(),\n // Ensure targetingId is string so that it will be placed in customDimensions\n \"TargetingId\": event.targetingId?.toString(),\n \"Variant\": event.variant?.name,\n \"VariantAssignmentReason\": event.variantAssignmentReason,\n };\n\n const metadata = event.feature?.telemetry?.metadata;\n if (metadata) {\n for (const key in metadata) {\n if (!(key in eventProperties)) {\n eventProperties[key] = metadata[key];\n }\n }\n }\n\n client.trackEvent({ name: \"FeatureEvaluation\" }, eventProperties);\n };\n}\n\n/**\n * Tracks a custom event using Application Insights, ensuring that the \"TargetingId\"\n * is included in the custom properties. If the \"TargetingId\" already exists in\n * the provided custom properties, it will be overwritten.\n *\n * @param client The Application Insights client instance used to track the event.\n * @param targetingId The unique targeting identifier that will be included in the custom properties.\n * @param event The event telemetry object to be tracked, containing event details.\n * @param customProperties (Optional) Additional properties to include in the event telemetry.\n */\nexport function trackEvent(client: ApplicationInsights, targetingId: string, event: IEventTelemetry, customProperties?: {[key: string]: any}): void {\n const properties = customProperties ? { ...customProperties } : {};\n // Ensure targetingId is string so that it will be placed in customDimensions\n properties[\"TargetingId\"] = targetingId?.toString();\n client.trackEvent(event, properties);\n}\n","// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nexport const VERSION = \"2.0.0-preview.1\";\n"],"names":[],"mappings":";;;;;;IAAA;IACA;IAMA;;;;IAIG;IACG,SAAU,wBAAwB,CAAC,MAA2B,EAAA;QAChE,OAAO,CAAC,KAAuB,KAAI;IAC/B,QAAA,MAAM,eAAe,GAAG;IACpB,YAAA,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,EAAE;IAChC,YAAA,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE;;IAEnC,YAAA,aAAa,EAAE,KAAK,CAAC,WAAW,EAAE,QAAQ,EAAE;IAC5C,YAAA,SAAS,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI;gBAC9B,yBAAyB,EAAE,KAAK,CAAC,uBAAuB;aAC3D,CAAC;YAEF,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,QAAQ,CAAC;YACpD,IAAI,QAAQ,EAAE;IACV,YAAA,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE;IACxB,gBAAA,IAAI,EAAE,GAAG,IAAI,eAAe,CAAC,EAAE;wBAC3B,eAAe,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;qBACxC;iBACJ;aACJ;YAED,MAAM,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,mBAAmB,EAAE,EAAE,eAAe,CAAC,CAAC;IACtE,KAAC,CAAC;IACN,CAAC;IAED;;;;;;;;;IASG;IACG,SAAU,UAAU,CAAC,MAA2B,EAAE,WAAmB,EAAE,KAAsB,EAAE,gBAAuC,EAAA;IACxI,IAAA,MAAM,UAAU,GAAG,gBAAgB,GAAG,EAAE,GAAG,gBAAgB,EAAE,GAAG,EAAE,CAAC;;QAEnE,UAAU,CAAC,aAAa,CAAC,GAAG,WAAW,EAAE,QAAQ,EAAE,CAAC;IACpD,IAAA,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACzC;;ICnDA;IACA;AAEO,UAAM,OAAO,GAAG;;;;;;;;;;"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@microsoft/feature-management-applicationinsights-browser",
3
+ "version": "2.0.0-preview.1",
4
+ "description": "Feature Management Application Insights Plugin for Browser provides a solution for sending feature flag evaluation events produced by the Feature Management library.",
5
+ "main": "./dist/umd/index.js",
6
+ "module": "./dist/esm/index.js",
7
+ "types": "types/index.d.ts",
8
+ "files": [
9
+ "dist/",
10
+ "types/",
11
+ "LICENSE",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "npm run link && npm run clean && rollup --config",
16
+ "clean": "rimraf dist types",
17
+ "link": "npm link ../feature-management",
18
+ "dev": "rollup --config --watch",
19
+ "lint": "eslint src/",
20
+ "fix-lint": "eslint src/ --fix"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/microsoft/FeatureManagement-JavaScript.git"
25
+ },
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/microsoft/FeatureManagement-JavaScript/issues"
29
+ },
30
+ "homepage": "https://github.com/microsoft/FeatureManagement-JavaScript#readme",
31
+ "devDependencies": {
32
+ "@rollup/plugin-typescript": "^11.1.5",
33
+ "@types/node": "^20.10.7",
34
+ "@typescript-eslint/eslint-plugin": "^6.18.1",
35
+ "@typescript-eslint/parser": "^6.18.1",
36
+ "eslint": "^8.56.0",
37
+ "rimraf": "^5.0.5",
38
+ "rollup": "^4.9.4",
39
+ "rollup-plugin-dts": "^6.1.0",
40
+ "tslib": "^2.6.2",
41
+ "typescript": "^5.3.3"
42
+ },
43
+ "dependencies": {
44
+ "@microsoft/applicationinsights-web": "^3.3.2",
45
+ "@microsoft/feature-management": "1.0.0-preview.1"
46
+ }
47
+ }
48
+
@@ -0,0 +1,26 @@
1
+ import { EvaluationResult } from '@microsoft/feature-management';
2
+ import { ApplicationInsights, IEventTelemetry } from '@microsoft/applicationinsights-web';
3
+
4
+ /**
5
+ * Creates a telemetry publisher that sends feature evaluation events to Application Insights.
6
+ * @param client The Application Insights telemetry client.
7
+ * @returns A callback function that takes an evaluation result and tracks an event with the evaluation details.
8
+ */
9
+ declare function createTelemetryPublisher(client: ApplicationInsights): (event: EvaluationResult) => void;
10
+ /**
11
+ * Tracks a custom event using Application Insights, ensuring that the "TargetingId"
12
+ * is included in the custom properties. If the "TargetingId" already exists in
13
+ * the provided custom properties, it will be overwritten.
14
+ *
15
+ * @param client The Application Insights client instance used to track the event.
16
+ * @param targetingId The unique targeting identifier that will be included in the custom properties.
17
+ * @param event The event telemetry object to be tracked, containing event details.
18
+ * @param customProperties (Optional) Additional properties to include in the event telemetry.
19
+ */
20
+ declare function trackEvent(client: ApplicationInsights, targetingId: string, event: IEventTelemetry, customProperties?: {
21
+ [key: string]: any;
22
+ }): void;
23
+
24
+ declare const VERSION = "2.0.0-preview.1";
25
+
26
+ export { VERSION, createTelemetryPublisher, trackEvent };