Skip to content

Commit 8bbf6b0

Browse files
update app insights example
1 parent 01a854f commit 8bbf6b0

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

articles/azure-app-configuration/feature-management-javascript-reference.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -673,18 +673,21 @@ If your application runs in the browser, install the [`"@microsoft/feature-manag
673673

674674
```typescript
675675
import { ApplicationInsights } from "@microsoft/applicationinsights-web"
676-
import { createTelemetryPublisher, trackEvent } from "@microsoft/feature-management-applicationinsights-browser"
676+
import { FeatureManager, ConfigurationObjectFeatureFlagProvider } from "@microsoft/feature-management";
677+
import { createTelemetryPublisher, trackEvent } from "@microsoft/feature-management-applicationinsights-browser";
677678

678679
const appInsights = new ApplicationInsights({ config: {
679-
connectionString: "InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE",
680+
connectionString: "<APPINSIGHTS_CONNECTION_STRING>"
680681
}});
681682
appInsights.loadAppInsights();
682683

683-
...
684-
const telemetryPublisher = createTelemetryPublisher(appInsights);
685-
const featureManager = new FeatureManager(ffProvider, { onFeatureEvaluated: telemetryPublisher});
684+
const publishTelemetry = createTelemetryPublisher(appInsights);
685+
const provider = new ConfigurationObjectFeatureFlagProvider(jsonObject);
686+
const featureManager = new FeatureManager(provider, {onFeatureEvaluated: publishTelemetry});
687+
688+
// FeatureEvaluation event will be emitted when a feature flag is evaluated
689+
featureManager.getVariant("TestFeature", {userId : TARGETING_ID}).then((variant) => { /* do something*/ });
686690

687-
...
688691
// Emit a custom event with targeting id attached.
689692
trackEvent(appInsights, TARGETING_ID, {name: "TestEvent"}, {"Tag": "Some Value"});
690693
```
@@ -694,18 +697,21 @@ trackEvent(appInsights, TARGETING_ID, {name: "TestEvent"}, {"Tag": "Some Value"}
694697
If your application runs in the Node.js, install the [`"@microsoft/feature-management-applicationinsights-node"`](https://www.npmjs.com/package/@microsoft/feature-management-applicationinsights-node) package. The following example shows how you can create a built-in Application Insights telemetry publisher and register it to the feature manager.
695698

696699
```typescript
697-
import appInsights from "applicationinsights"
698-
import { createTelemetryPublisher, trackEvent } from "@microsoft/feature-management-applicationinsights-node"
700+
const appInsights = require("applicationinsights");
701+
appInsights.setup(process.env.APPINSIGHTS_CONNECTION_STRING).start();
702+
703+
const { FeatureManager, ConfigurationObjectFeatureFlagProvider } = require("@microsoft/feature-management");
704+
const { createTelemetryPublisher, trackEvent } = require("@microsoft/feature-management-applicationinsights-node");
699705

700-
appInsights.setup().start(); // for more information: https://learn.microsoft.com/azure/azure-monitor/app/nodejs#basic-usage
706+
const publishTelemetry = createTelemetryPublisher(appInsights.defaultClient);
707+
const provider = new ConfigurationObjectFeatureFlagProvider(jsonObject);
708+
const featureManager = new FeatureManager(provider, {onFeatureEvaluated: publishTelemetry});
701709

702-
...
703-
const telemetryPublisher = createTelemetryPublisher(appInsights.defaultClient);
704-
const featureManager = new FeatureManager(ffProvider, { onFeatureEvaluated: telemetryPublisher});
710+
// FeatureEvaluation event will be emitted when a feature flag is evaluated
711+
featureManager.getVariant("TestFeature", {userId : "<TARGETING_ID>"}).then((variant) => { /* do something*/ });
705712

706-
...
707713
// Emit a custom event with targeting id attached.
708-
trackEvent(appInsights.defaultClient, TARGETING_ID, {name: "TestEvent"});
714+
trackEvent(appInsights.defaultClient, "<TARGETING_ID>", {name: "TestEvent", properties: {"Tag": "Some Value"}});
709715
```
710716

711717
---

0 commit comments

Comments
 (0)