|
| 1 | +# Datadog OpenFeature Browser |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +### For Customers (Recommended) |
| 6 | + |
| 7 | +**We do not recommend pinning to an exact _preview_ version:** |
| 8 | + |
| 9 | +Use the `preview` tag for the latest preview version: |
| 10 | + |
| 11 | +```bash |
| 12 | +npm install @datadog/openfeature-browser@preview |
| 13 | +``` |
| 14 | + |
| 15 | +This will install the latest _preview_ version. |
| 16 | + |
| 17 | +### Specific Version |
| 18 | + |
| 19 | +You can also install a specific _preview_ version: |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install @datadog/openfeature-browser@0.1.0-preview.x |
| 23 | +``` |
| 24 | + |
| 25 | +## Quick Start |
| 26 | + |
| 27 | +The main entry point is `DatadogProvider`, which is a provider for the [OpenFeature Web SDK](https://openfeature.dev/docs/reference/technologies/client/web/). |
| 28 | + |
| 29 | +```javascript |
| 30 | +import { DatadogProvider } from '@datadog/openfeature-browser' |
| 31 | +import { OpenFeature } from '@openfeature/web-sdk' |
| 32 | + |
| 33 | +// Initialize the provider |
| 34 | +const provider = new DatadogProvider({ |
| 35 | + clientToken: 'your-datadog-client-token', |
| 36 | + enableExposureLogging: true, |
| 37 | + site: 'datadoghq.com', |
| 38 | +}) |
| 39 | + |
| 40 | +// Set the provider |
| 41 | +await OpenFeature.setProvider(provider) |
| 42 | + |
| 43 | +// Get a client and evaluate flags |
| 44 | +const client = OpenFeature.getClient() |
| 45 | +const flagValue = await client.getBooleanValue('my-flag', false) |
| 46 | +``` |
| 47 | + |
| 48 | +## Configuration |
| 49 | + |
| 50 | +```javascript |
| 51 | +const provider = new DatadogProvider({ |
| 52 | + // Required |
| 53 | + clientToken: 'pub_...', // Your Datadog client token |
| 54 | + site: 'datadoghq.com', // Datadog site (datadoghq.com, datadoghq.eu, etc.) |
| 55 | + env: 'production', // Environment |
| 56 | + |
| 57 | + // Optional Datadog configuration |
| 58 | + service: 'my-service', // Service name |
| 59 | + version: '1.0.0', // Application version |
| 60 | + applicationId: 'app-id', // Your application ID for RUM attribution |
| 61 | + |
| 62 | + // Enable exposure logging |
| 63 | + enableExposureLogging: true, |
| 64 | +}) |
| 65 | +``` |
| 66 | + |
| 67 | +## Usage Examples |
| 68 | + |
| 69 | +### Flag Evaluation |
| 70 | + |
| 71 | +```javascript |
| 72 | +const client = OpenFeature.getClient() |
| 73 | + |
| 74 | +// Boolean flags |
| 75 | +const showFeature = await client.getBooleanValue('show-new-feature', false) |
| 76 | + |
| 77 | +// String flags |
| 78 | +const theme = await client.getStringValue('app-theme', 'light') |
| 79 | + |
| 80 | +// Number flags |
| 81 | +const timeout = await client.getNumberValue('request-timeout', 5000) |
| 82 | + |
| 83 | +// Object flags |
| 84 | +const config = await client.getObjectValue('feature-config', {}) |
| 85 | +``` |
| 86 | + |
| 87 | +### Using Evaluation Context |
| 88 | + |
| 89 | +Context must be set globally before flag evaluation and affects all subsequent evaluations: |
| 90 | + |
| 91 | +```javascript |
| 92 | +// Set global context (async operation) |
| 93 | +await OpenFeature.setContext({ |
| 94 | + targetingKey: 'user-123', |
| 95 | + user: { id: 'user-123', email: 'user@example.com' }, |
| 96 | +}) |
| 97 | + |
| 98 | +// Now evaluate flags with the context |
| 99 | +const result = await client.getBooleanDetails('premium-feature', false) |
| 100 | +console.log(result.value) // Flag value |
| 101 | +console.log(result.reason) // Evaluation reason |
| 102 | +``` |
| 103 | + |
| 104 | +## End-user license agreement |
| 105 | + |
| 106 | +https://www.datadoghq.com/legal/eula |
0 commit comments