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
#Customer intent: I want to control feature availability in my app by using the Feature Management library.
15
15
---
16
16
17
-
# Python Feature Management
17
+
# Python feature management
18
18
19
19
:::zone target="docs" pivot="stable-version"
20
20
@@ -34,31 +34,31 @@ Feature flags provide a way for Python applications to turn features on or off d
34
34
Here are some of the benefits of using Python feature management library:
35
35
36
36
* A common convention for feature management
37
-
* Low barrier-to-entry
37
+
* Low barrier to entry
38
38
* Supports JSON feature flag setup
39
-
* Feature Flag lifetime management
39
+
* Feature flag lifetime management
40
40
* Configuration values can change in real-time; feature flags can be consistent across the entire request
41
-
* Simple to Complex Scenarios Covered
41
+
* Simple to complex scenarios covered
42
42
* Toggle on/off features through declarative configuration file
43
43
* Dynamically evaluate state of feature based on call to server
44
44
45
45
The Python feature management library is open source. For more information, visit the [GitHub repo](https://github.com/microsoft/FeatureManagement-Python).
46
46
47
-
## Feature Flags
47
+
## Feature flags
48
48
Feature flags are composed of two parts, a name and a list of feature-filters that are used to turn on the feature.
49
49
50
-
### Feature Filters
51
-
Feature filters define a scenario for when a feature should be enabled. When a feature is evaluated for whether it is on or off, its list of feature filters is traversed until one of the filters decides the feature should be enabled. At this point, the feature is considered enabled and traversal through the feature filters stops. If no feature filter indicates that the feature should be enabled, it considered disabled.
50
+
### Feature filters
51
+
Feature filters define a scenario for when a feature should be enabled. When a feature is evaluated for whether it is on or off, its list of feature filters is traversed until one of the filters decides the feature should be enabled. At this point, the feature is considered enabled and traversal through the feature filters stops. If no feature filter indicates that the feature should be enabled, it's considered disabled.
52
52
53
53
As an example, a Microsoft Edge browser feature filter could be designed. This feature filter would activate any features attached to it, as long as an HTTP request is coming from Microsoft Edge.
54
54
55
-
### Feature Flag Configuration
55
+
### Feature flag configuration
56
56
57
-
A Python dictionary is used to define feature flags. The dictionary is composed of feature names as keys and feature flag objects as values. The feature flag object is a dictionary that contains an `EnabledFor` key. The `EnabledFor` key is a list of feature filters that are used to determine if the feature should be enabled
57
+
A Python dictionary is used to define feature flags. The dictionary is composed of feature names as keys and feature flag objects as values. The feature flag object is a dictionary that contains an `EnabledFor` key. The `EnabledFor` key is a list of feature filters that are used to determine if the feature should be enabled.
58
58
59
-
### Feature Flag Declaration
59
+
### Feature flag declaration
60
60
61
-
The feature management library supports json as a feature flag source. Below we have an example of the format used to set up feature flags in a json file.
61
+
The feature management library supports json as a feature flag source. Below we have an example of the format used to set up feature flags in a JSON file.
62
62
63
63
```json
64
64
{
@@ -98,7 +98,7 @@ The detailed schema of the `feature_management` section can be found [here](http
98
98
99
99
**Advanced:** The usage of colon ':' is forbidden in feature flag names.
100
100
101
-
#### On/Off Declaration
101
+
#### On/off declaration
102
102
103
103
The following snippet demonstrates an alternative way to define a feature that can be used for on/off features.
104
104
```json
@@ -118,7 +118,7 @@ The following snippet demonstrates an alternative way to define a feature that c
118
118
}
119
119
```
120
120
121
-
#### RequirementType
121
+
#### Requirement_type
122
122
123
123
The `requirement_type` property of a feature flag is used to determine if the filters should use `Any` or `All` logic when evaluating the state of a feature. If `requirement_type` isn't specified, the default value is `Any`.
124
124
@@ -174,7 +174,7 @@ if feature_manager.is_enabled("FeatureX"):
174
174
175
175
The `feature_flags` provided to `FeatureManager` can either be the `AzureAppConfigurationProvider` or a dictionary of feature flags.
176
176
177
-
## Implementing a Feature Filter
177
+
## Implementing a feature filter
178
178
179
179
Creating a feature filter provides a way to enable features based on criteria that you define. To implement a feature filter, the `FeatureFilter` interface must be implemented. `FeatureFilter` has a single method named `evaluate`. When a feature specifies that it can be enabled for a feature filter, the `evaluate` method is called. If `evaluate` returns `true`, it means the feature should be enabled.
Feature filters are registered by providing when creating `FeatureManager` with `feature_filters`. If a custom feature filter needs any context, they can be passed in when calling `is_enabled` using `kwargs`.
188
188
189
-
### Filter Alias Attribute
189
+
### Filter alias attribute
190
190
191
191
When a feature filter is registered for a feature flag, the name of the filter is used as the alias by default.
192
192
193
193
The identifier for the feature filter can be overridden by using the `@FeatureFilter.alias("MyFilter")`. A feature filter can be decorated with this attribute to declare the name that should be used in configuration to reference this feature filter within a feature flag.
194
194
195
-
### Missing Feature Filters
195
+
### Missing feature filters
196
196
197
-
If a feature, configured to be enabled, for a specific feature filter and that feature filter isn't registered, an`ValueError` exception is raised when the feature is evaluated.
197
+
If a feature is configured to be enabled for a specific feature filter and that feature filter isn't registered, a`ValueError` exception is raised when the feature is evaluated.
198
198
199
-
## Built-In Feature Filters
199
+
## Built-in feature filters
200
200
201
201
There are a two feature filters that come with the `FeatureManagement` package: `TimeWindowFilter`, and `TargetingFilter`.
202
202
@@ -256,7 +256,6 @@ This filter provides the capability to enable a feature for a target audience. A
When defining an Audience, users and groups can be excluded from the audience. Exclusions are useful for when a feature is being rolled out to a group of users, but a few users or groups need to be excluded from the rollout. Exclusion is defined by adding a list of users and groups to the `Exclusion` property of the audience.
290
+
When defining an audience, users and groups can be excluded from the audience. Exclusions are useful for when a feature is being rolled out to a group of users, but a few users or groups need to be excluded from the rollout. Exclusion is defined by adding a list of users and groups to the `Exclusion` property of the audience.
292
291
293
292
```json
294
293
"Audience": {
@@ -319,7 +318,7 @@ In the above example, the feature is enabled for users named `Jeff` and `Alicia`
319
318
320
319
When new features are added to an application, there may come a time when a feature has multiple different proposed design options. A common solution for deciding on a design is some form of A/B testing. A/B testing involves providing a different version of the feature to different segments of the user base and choosing a version based on user interaction. In this library, this functionality is enabled by representing different configurations of a feature with variants.
321
320
322
-
Variants enable a feature flag to become more than a simple on/off flag. A variant represents a value of a feature flag that can be a string, a number, a boolean, or even a configuration object. A feature flag that declares variants should define under what circumstances each variant should be used, which is covered in greater detail in the [Allocating Variants](#allocating-variants) section.
321
+
Variants enable a feature flag to become more than a simple on/off flag. A variant represents a value of a feature flag that can be a string, a number, a boolean, or even a configuration object. A feature flag that declares variants should define under what circumstances each variant should be used, which is covered in greater detail in the [Allocating variants](#allocating-variants) section.
323
322
324
323
```python
325
324
classVariant:
@@ -344,7 +343,7 @@ class Variant:
344
343
returnself._configuration
345
344
```
346
345
347
-
### Getting Variants
346
+
### Getting variants
348
347
349
348
For each feature, a variant can be retrieved using the `FeatureManager`'s `get_variant` method.
The variant returned is dependent on the user currently being evaluated, and that information is obtained from an instance of `TargetingContext`.
361
360
362
-
### Variant Feature Flag Declaration
361
+
### Variant feature flag declaration
363
362
364
-
Compared to normal feature flags, variant feature flags have two more properties: `variants`and`allocation`. The `variants`propertyis an array that contains the variants defined for this feature. The `allocation`property defines how these variants should be allocated for the feature. Just like declaring normal feature flags, you can set up variant feature flags in a jsonfile. Here's an example of a variant feature flag.
363
+
Compared to normal feature flags, variant feature flags have two more properties: `variants`and`allocation`. The `variants`propertyis an array that contains the variants defined for this feature. The `allocation`property defines how these variants should be allocated for the feature. Just like declaring normal feature flags, you can set up variant feature flags in a JSONfile. Here's an example of a variant feature flag.
365
364
366
365
```json
367
366
{
@@ -395,7 +394,7 @@ Compared to normal feature flags, variant feature flags have two more properties
395
394
}
396
395
```
397
396
398
-
#### Defining Variants
397
+
#### Defining variants
399
398
400
399
Each variant has two properties: a name and a configuration. The name is used to refer to a specific variant, and the configuration is the value of that variant. The configuration can be set using `configuration_value`property. `configuration_value`is an inline configuration that can be a string, number, boolean, or configuration object. If `configuration_value` isn't specified, the returned variant's `Configuration`propertyis`None`.
401
400
@@ -427,7 +426,7 @@ A list of all possible variants is defined for each feature under the `variants`
427
426
}
428
427
```
429
428
430
-
#### Allocating Variants
429
+
#### Allocating variants
431
430
432
431
The process of allocating a feature's variants is determined by the `allocation` property of the feature.
433
432
@@ -490,9 +489,9 @@ If the feature is enabled, the feature manager checks the `user`, `group`, and `
490
489
Allocation logic is similar to the [Microsoft.Targeting](#microsofttargeting) feature filter, but there are some parameters that are present in targeting that aren't in allocation, and vice versa. The outcomes of targeting and allocation aren't related.
491
490
492
491
493
-
### Overriding Enabled State with a Variant
492
+
### Overriding enabled state with a variant
494
493
495
-
You can use variants to override the enabled state of a feature flag. Overriding gives variants an opportunity to extend the evaluation of a feature flag. When calling `is_enabled` on a flag with variants, the Feature Manager will check if the variant assigned to the current user is configured to override the result. Overriding is done using the optional variant property`status_override`. By default, this propertyisset to `None`, which means the variant doesn't affect whether the flag is considered enabled or disabled. Setting `status_override` to `Enabled` allows the variant, when chosen, to override a flag to be enabled. Setting `status_override` to `Disabled` provides the opposite functionality, therefore disabling the flag when the variant is chosen. A feature with an `enabled` state of `false` can't be overridden.
494
+
You can use variants to override the enabled state of a feature flag. Overriding gives variants an opportunity to extend the evaluation of a feature flag. When calling `is_enabled` on a flag with variants, the feature manager will check if the variant assigned to the current user is configured to override the result. Overriding is done using the optional variant property`status_override`. By default, this propertyisset to `None`, which means the variant doesn't affect whether the flag is considered enabled or disabled. Setting `status_override` to `Enabled` allows the variant, when chosen, to override a flag to be enabled. Setting `status_override` to `Disabled` provides the opposite functionality, therefore disabling the flag when the variant is chosen. A feature with an `enabled` state of `false` can't be overridden.
496
495
497
496
If you're using a feature flag with binary variants, the `status_override` property can be helpful. It allows you to continue using APIs like `is_enabled` in your application, all while benefiting from the new features that come with variants, such as percentile allocation and seed.
498
497
@@ -536,7 +535,7 @@ When a feature flag change is deployed, it's often important to analyze its effe
536
535
537
536
These types of questions can be answered through the emission and analysis of feature flag evaluation events. This library optionally enables `AzureMonitor` produce tracing telemetry during feature flag evaluation via `OpenTelemetry`.
538
537
539
-
### Enabling Telemetry
538
+
### Enabling telemetry
540
539
541
540
By default, feature flags don't have telemetry emitted. To publish telemetry for a given feature flag, the flag _MUST_ declare that it's enabled for telemetry emission.
542
541
@@ -573,11 +572,12 @@ In addition, when creating `FeatureManager`, a callback must be registered to ha
The feature management library provides a built-in telemetry publisher that sends feature flag evaluation data to [Application Insights](/azure/azure-monitor/app/app-insights-overview). To enable Application Insights, the feature management library can be installed with Azure Monitor, `pip install FeatureManagement[AzureMonitor]`. Which installs the package`azure-monitor-events-extension` package, which is used to style telemetry to Application Insights using OpenTelemetry.
577
+
The feature management library provides a built-in telemetry publisher that sends feature flag evaluation data to [Application Insights](/azure/azure-monitor/app/app-insights-overview). To enable Application Insights, the feature management library can be installed with Azure Monitor via `pip install FeatureManagement[AzureMonitor]`. This command installs the `azure-monitor-events-extension` package, which is used to style telemetry to Application Insights using OpenTelemetry.
579
578
580
-
NOTE: The extra only adds the telemetry to the Open Telemetry pipeline. Registering Application Insights is still required.
579
+
> [!NOTE]
580
+
> The `azure-monitor-events-extension` package only adds the telemetry to the Open Telemetry pipeline. Registering Application Insights is still required.
581
581
582
582
```python
583
583
from azure.monitor.opentelemetry import configure_azure_monitor
@@ -587,7 +587,7 @@ configure_azure_monitor(
587
587
)
588
588
```
589
589
590
-
### Custom Telemetry Publishing
590
+
### Custom telemetry publishing
591
591
592
592
Because the telemetry callback is a function, it can be customized to publish telemetry to any desired destination. For example, telemetry could be published to a logging service, a database, or a custom telemetry service.
0 commit comments