You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/feature-management-dotnet-reference.md
+31-18Lines changed: 31 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1329,7 +1329,7 @@ When a feature flag change is deployed, it's often important to analyze its effe
1329
1329
* Which variant is a particular user seeing?
1330
1330
1331
1331
1332
-
These types of questions can be answered through the emission and analysis of feature flag evaluation events. This library supports emitting these events through telemetry publishers. One or many telemetry publishers can be registered to publish events whenever feature flags are evaluated.
1332
+
These types of questions can be answered through the emission and analysis of feature flag evaluation events. This library uses [`System.Diagnostics.Activity`](https://learn.microsoft.com/dotnet/api/system.diagnostics.activity) API to produce tracing telemetry during feature flag evaluation.
1333
1333
1334
1334
### Enabling Telemetry
1335
1335
@@ -1360,41 +1360,54 @@ The `telemetry` section of a feature flag has the following properties:
1360
1360
| Property | Description |
1361
1361
|----------------|----------------|
1362
1362
|`enabled`| Specifies whether telemetry should be published for the feature flag. |
1363
-
|`metadata`|A collection of key-value pairs, modeled as a dictionary, that can be used to attach custom metadata about the feature flag to evaluation events.|
1363
+
|`metadata`|A collection of key-value pairs, modeled as a dictionary, that can be used to attach custom metadata about the feature flag to evaluation events.
1364
1364
1365
-
### Custom Telemetry Publishers
1365
+
### Custom Telemetry Publishing
1366
1366
1367
-
Custom handling of feature flag telemetry is made possible by implementing an `ITelemetryPublisher` and registering it in the feature manager. Whenever a feature flag that has telemetry enabled is evaluated, the registered telemetry publisher gets a chance to publish the corresponding evaluation event.
1367
+
The feature manager has its own `ActivitySource`with name "Microsoft.FeatureManagement". If`telemetry` is enabled for a feature flag, whenever the evaluation ofthis feature flag is started, the feature manager will start an `Activity`. When the feature flag evaluation is finished, the feature manager will add an `ActivityEvent` called "FeatureFlag" to the `Activity.Current`. The"FeatureFlag"event will have tags which include the information about the feature flag evaluation.
1368
+
1369
+
To enable custom telemetry publishing, you should create an [`ActivityListener`](https://learn.microsoft.com/dotnet/api/system.diagnostics.activitylistener) and listen to `Microsoft.FeatureManagement` activity source. Here is an example showing how to listen to the feature management activity source and add a callback when feature evaluation is done.
if (evaluationEvent.HasValue && evaluationEvent.Value.Tags.Any())
1381
+
{
1382
+
// Do something.
1383
+
}
1384
+
}
1385
+
});
1374
1386
```
1375
1387
1376
-
The `EvaluationEvent` type can be found [here](https://github.com/microsoft/FeatureManagement-Dotnet/blob/preview/src/Microsoft.FeatureManagement/Telemetry/EvaluationEvent.cs) for reference.
1388
+
For more information, please go to [Collect a distributed trace](https://learn.microsoft.com/dotnet/core/diagnostics/distributed-tracing-collection-walkthroughs).
1389
+
1390
+
### Application Insights Telemetry Publisher
1377
1391
1378
-
Registering telemetry publishers is done when calling `AddFeatureManagement()`. Here's an example setting up feature management to emit telemetry with an implementation of `ITelemetryPublisher` called `MyTelemetryPublisher`.
1392
+
The `Microsoft.FeatureManagement.Telemetry.ApplicationInsights`package provides a built-intelemetry publisher that sends feature flag evaluation data to [Application Insights](/azure/azure-monitor/app/app-insights-overview). To take advantage ofthis, add a reference to the package and register the Application Insights telemetry publisher as shown below.
1379
1393
1380
1394
``` C#
1381
1395
builder.services
1382
1396
.AddFeatureManagement()
1383
-
.AddTelemetryPublisher<MyTelemetryPublisher>();
1397
+
.AddApplicationInsightsTelemetryPublisher();
1384
1398
```
1385
1399
1386
-
### Application Insights Telemetry Publisher
1387
-
1388
-
The `Microsoft.FeatureManagement.Telemetry.ApplicationInsights` package provides a built-in telemetry publisher implementation that sends feature flag evaluation data to [Application Insights](/azure/azure-monitor/app/app-insights-overview). To take advantage of this, add a reference to the package and register the Application Insights telemetry publisher as shown below.
1400
+
The `Microsoft.FeatureManagement.Telemetry.ApplicationInsights`package provides the [`TargetingTelemetryInitializer`](https://github.com/microsoft/FeatureManagement-Dotnet/blob/preview/src/Microsoft.FeatureManagement.Telemetry.ApplicationInsights/TargetingTelemetryInitializer.cs) which implements the [ITelemetryInitializer](https://learn.microsoft.com/azure/azure-monitor/app/api-filtering-sampling#addmodify-properties-itelemetryinitializer). The `TargetingTelemetryInitializer` will extract targeting information from current activity's baggage and add it to Application Insights telemetry properties.
> The base `Microsoft.FeatureManagement` package doesn't include this telemetry publisher.
1406
+
To enable persistance of targeting context in the current activity, you can use the [`TargetingHttpContextMiddleware`](https://github.com/microsoft/FeatureManagement-Dotnet/blob/preview/src/Microsoft.FeatureManagement.AspNetCore/TargetingHttpContextMiddleware.cs).
An example of its usage can be found in the [EvaluationDataToApplicationInsights](https://github.com/microsoft/FeatureManagement-Dotnet/tree/preview/examples/EvaluationDataToApplicationInsights) example.
0 commit comments