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
Feature Management is a library for enabling/disabling features at runtime.
6
-
Developers can use feature flags in simple use cases like conditional statement to more advanced scenarios like conditionally adding routes.
5
+
Feature management provides a way to develop and expose application functionality based on features. Many applications have special requirements when a new feature is developed such as when the feature should be enabled and under what conditions. This library provides a way to define these relationships, and also integrates into common JavaScript code patterns to make exposing these features possible.
7
6
8
7
## Getting Started
9
8
10
-
### Prerequisites
9
+
[Azure App Configuration Quickstart](https://learn.microsoft.com/azure/azure-app-configuration/quickstart-feature-flag-javascript): A quickstart guide about how to integrate feature flags from Azure App Configuration into your JavaScript applications.
11
10
12
-
- Node.js LTS version
11
+
[Feature Overview](https://learn.microsoft.com/azure/azure-app-configuration/feature-management-overview#feature-development-status): This document provides a feature status overview.
12
+
13
+
[Feature Reference](https://learn.microsoft.com/azure/azure-app-configuration/feature-management-javascript-reference): This document provides a full feature rundown.
13
14
14
15
### Usage
15
16
16
-
You can use feature flags from the Azure App Configuration service, local files or any other sources.
17
+
You can use feature flags from the Azure App Configuration service, local files or any other sources. For more information, please go to [Feature flag configuration](https://learn.microsoft.com/azure/azure-app-configuration/feature-management-javascript-reference#feature-flag-configuration).
17
18
18
19
#### Use feature flags from Azure App Configuration
19
20
20
21
The App Configuration JavaScript provider provides feature flags in as a `Map` object.
21
22
A builtin `ConfigurationMapFeatureFlagProvider` helps to load feature flags in this case.
22
23
23
24
```js
24
-
constappConfig=awaitload(connectionString, {featureFlagOptions}); // load feature flags from Azure App Configuration service
# Examples for Microsoft Feature Management for JavaScript
2
+
3
+
These examples show how to use the Microsoft Feature Management in an express application.
4
+
5
+
## Prerequisites
6
+
7
+
The examples are compatible with [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule).
8
+
9
+
## Setup & Run
10
+
11
+
1. Go to `src/feature-management` under the root folder and run:
12
+
13
+
```bash
14
+
npm run install
15
+
npm run build
16
+
```
17
+
18
+
1. Go back to `examples/express-app` and install the dependencies using `npm`:
19
+
20
+
```bash
21
+
npm install
22
+
```
23
+
24
+
1. Run the examples:
25
+
26
+
```bash
27
+
node server.mjs
28
+
```
29
+
30
+
1. Visit `http://localhost:3000/Beta` and use `userId` and `groups` query to specify the targeting context (e.g. /Beta?userId=Jeff or /Beta?groups=Admin).
31
+
32
+
- If you are not targeted, you will get the message "Page not found".
33
+
34
+
- If you are targeted, you will get the message "Welcome to the Beta page!".
35
+
36
+
## Targeting
37
+
38
+
The targeting mechanism uses the `exampleTargetingContextAccessor` to extract the targeting context from the request. This functionretrieves the userId and groups from the query parameters of the request.
39
+
40
+
```javascript
41
+
const exampleTargetingContextAccessor = {
42
+
getTargetingContext: () => {
43
+
const req = requestAccessor.getStore();
44
+
// read user and groups from request query data
45
+
const { userId, groups } = req.query;
46
+
// return aa ITargetingContext with the appropriate user info
This allows you to get ambient targeting context while doing feature flag evaluation.
64
+
65
+
### Request Accessor
66
+
67
+
The `requestAccessor` is an instance of `AsyncLocalStorage` from the `async_hooks` module. It is used to store the request object in asynchronous local storage, allowing it to be accessed throughout the lifetime of the request. This is particularly useful foraccessing request-specific datain asynchronous operations. For more information, please go to https://nodejs.org/api/async_context.html
68
+
69
+
```javascript
70
+
import { AsyncLocalStorage } from "async_hooks";
71
+
const requestAccessor = new AsyncLocalStorage();
72
+
```
73
+
74
+
Middleware is used to store the request object in the AsyncLocalStorage:
Copy file name to clipboardExpand all lines: src/feature-management-applicationinsights-browser/README.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
# Microsoft Feature Management Application Insights Plugin for Browser
2
2
3
-
Feature Management Application Insights Plugin for Browser provides a solution for sending feature flag evaluation events produced by the Feature Management library.
3
+
Feature Management Application Insights Plugin for Browser provides a solution for sending feature flag evaluation telemetry produced by the [`@microsoft/feature-management`](https://www.npmjs.com/package/@microsoft/feature-management) library.
4
4
5
5
## Getting Started
6
6
7
+
For more information, please go to [Feature reference](https://learn.microsoft.com/azure/azure-app-configuration/feature-management-javascript-reference#application-insights-integration).
"description": "Feature Management Application Insights Plugin for Browser provides a solution for sending feature flag evaluation events produced by the Feature Management library.",
0 commit comments