@@ -673,18 +673,21 @@ If your application runs in the browser, install the [`"@microsoft/feature-manag
673
673
674
674
``` typescript
675
675
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" ;
677
678
678
679
const appInsights = new ApplicationInsights ({ config: {
679
- connectionString: " InstrumentationKey=YOUR_INSTRUMENTATION_KEY_GOES_HERE " ,
680
+ connectionString: " <APPINSIGHTS_CONNECTION_STRING> "
680
681
}});
681
682
appInsights .loadAppInsights ();
682
683
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*/ });
686
690
687
- ...
688
691
// Emit a custom event with targeting id attached.
689
692
trackEvent (appInsights , TARGETING_ID , {name: " TestEvent" }, {" Tag" : " Some Value" });
690
693
```
@@ -694,18 +697,21 @@ trackEvent(appInsights, TARGETING_ID, {name: "TestEvent"}, {"Tag": "Some Value"}
694
697
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.
695
698
696
699
``` 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" );
699
705
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 });
701
709
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*/ });
705
712
706
- ...
707
713
// 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 " } });
709
715
```
710
716
711
717
---
0 commit comments