0
# Feature Flag Integrations
1
2
Integrations for feature flag providers including LaunchDarkly, OpenFeature, Statsig, and Unleash, allowing automatic tracking of feature flag evaluations and usage in your application.
3
4
## Capabilities
5
6
### LaunchDarkly Integration
7
8
Automatic instrumentation for LaunchDarkly feature flag evaluations.
9
10
```typescript { .api }
11
/**
12
* Create LaunchDarkly integration for automatic feature flag tracking
13
* @param options - LaunchDarkly integration configuration options
14
* @returns LaunchDarkly integration instance
15
*/
16
function launchDarklyIntegration(options?: LaunchDarklyOptions): Integration;
17
18
/**
19
* Build a flag used handler for LaunchDarkly client
20
* @param client - Sentry client instance
21
* @returns Flag used handler function
22
*/
23
function buildLaunchDarklyFlagUsedHandler(client: Client): FlagUsedHandler;
24
```
25
26
**Usage Examples:**
27
28
```typescript
29
import * as Sentry from "@sentry/node";
30
import * as ld from "@launchdarkly/node-server-sdk";
31
32
// Initialize with LaunchDarkly integration
33
Sentry.init({
34
dsn: "YOUR_DSN",
35
integrations: [
36
Sentry.launchDarklyIntegration({
37
captureFlags: true, // Include flag keys and values in context
38
captureVariations: true, // Include variation details
39
}),
40
],
41
});
42
43
// LaunchDarkly client with Sentry handler
44
const ldClient = ld.init("YOUR_SDK_KEY", {
45
hooks: {
46
flagUsed: Sentry.buildLaunchDarklyFlagUsedHandler(Sentry.getClient()),
47
},
48
});
49
50
await ldClient.waitForInitialization();
51
52
// Feature flag evaluations will be automatically tracked
53
const showFeature = await ldClient.variation("show-feature", user, false);
54
const featureConfig = await ldClient.variationDetail("feature-config", user, {});
55
```
56
57
### OpenFeature Integration
58
59
Automatic instrumentation for OpenFeature providers and flag evaluations.
60
61
```typescript { .api }
62
/**
63
* Create OpenFeature integration for automatic feature flag tracking
64
* @param options - OpenFeature integration configuration options
65
* @returns OpenFeature integration instance
66
*/
67
function openFeatureIntegration(options?: OpenFeatureOptions): Integration;
68
69
/**
70
* OpenFeature integration hook type
71
*/
72
type OpenFeatureIntegrationHook = {
73
after: (hookContext: HookContext, details: EvaluationDetails) => void;
74
error: (hookContext: HookContext, error: Error) => void;
75
};
76
```
77
78
**Usage Examples:**
79
80
```typescript
81
import * as Sentry from "@sentry/node";
82
import { OpenFeature, InMemoryProvider } from "@openfeature/server-sdk";
83
84
// Initialize with OpenFeature integration
85
Sentry.init({
86
dsn: "YOUR_DSN",
87
integrations: [
88
Sentry.openFeatureIntegration({
89
captureFlags: true,
90
captureProviderInfo: true, // Include provider information
91
}),
92
],
93
});
94
95
// Set up OpenFeature provider
96
OpenFeature.setProvider(new InMemoryProvider({
97
"show-feature": { variants: { on: true, off: false }, defaultVariant: "off" },
98
}));
99
100
const client = OpenFeature.getClient();
101
102
// Feature flag evaluations will be automatically tracked
103
const showFeature = await client.getBooleanValue("show-feature", false, { userId: "123" });
104
const featureVariant = await client.getStringValue("feature-variant", "default", { userId: "123" });
105
```
106
107
### Statsig Integration
108
109
Automatic instrumentation for Statsig feature flags and experiments.
110
111
```typescript { .api }
112
/**
113
* Create Statsig integration for automatic feature flag and experiment tracking
114
* @param options - Statsig integration configuration options
115
* @returns Statsig integration instance
116
*/
117
function statsigIntegration(options?: StatsigOptions): Integration;
118
```
119
120
**Usage Examples:**
121
122
```typescript
123
import * as Sentry from "@sentry/node";
124
import Statsig from "statsig-node";
125
126
// Initialize with Statsig integration
127
Sentry.init({
128
dsn: "YOUR_DSN",
129
integrations: [
130
Sentry.statsigIntegration({
131
captureGates: true, // Include feature gate evaluations
132
captureConfigs: true, // Include dynamic config evaluations
133
captureExperiments: true, // Include experiment assignments
134
}),
135
],
136
});
137
138
// Initialize Statsig
139
await Statsig.initialize("YOUR_SERVER_SECRET_KEY");
140
141
const user = { userID: "123", email: "user@example.com" };
142
143
// Feature flag evaluations will be automatically tracked
144
const showFeature = Statsig.checkGate(user, "show_new_feature");
145
const config = Statsig.getConfig(user, "app_config");
146
const experiment = Statsig.getExperiment(user, "button_color_test");
147
```
148
149
### Unleash Integration
150
151
Automatic instrumentation for Unleash feature toggle evaluations.
152
153
```typescript { .api }
154
/**
155
* Create Unleash integration for automatic feature toggle tracking
156
* @param options - Unleash integration configuration options
157
* @returns Unleash integration instance
158
*/
159
function unleashIntegration(options?: UnleashOptions): Integration;
160
```
161
162
**Usage Examples:**
163
164
```typescript
165
import * as Sentry from "@sentry/node";
166
import { initialize, isEnabled, getVariant } from "unleash-client";
167
168
// Initialize with Unleash integration
169
Sentry.init({
170
dsn: "YOUR_DSN",
171
integrations: [
172
Sentry.unleashIntegration({
173
captureToggles: true, // Include toggle evaluations
174
captureVariants: true, // Include variant selections
175
}),
176
],
177
});
178
179
// Initialize Unleash client
180
const unleash = initialize({
181
url: "https://your-unleash-instance.com/api/",
182
appName: "my-node-app",
183
instanceId: "my-unique-instance-id",
184
});
185
186
await unleash.start();
187
188
const unleashContext = {
189
userId: "123",
190
sessionId: "session-123",
191
remoteAddress: "127.0.0.1",
192
};
193
194
// Feature toggle evaluations will be automatically tracked
195
const showFeature = isEnabled("show_new_feature", unleashContext);
196
const variant = getVariant("feature_variant", unleashContext);
197
```
198
199
### Generic Feature Flags Integration
200
201
General-purpose feature flags integration for custom providers.
202
203
```typescript { .api }
204
/**
205
* Create generic feature flags integration for custom flag tracking
206
* @param options - Feature flags integration configuration options
207
* @returns Feature flags integration instance
208
*/
209
function featureFlagsIntegration(options?: FeatureFlagsOptions): Integration;
210
```
211
212
**Usage Examples:**
213
214
```typescript
215
import * as Sentry from "@sentry/node";
216
217
// Initialize with generic feature flags integration
218
Sentry.init({
219
dsn: "YOUR_DSN",
220
integrations: [
221
Sentry.featureFlagsIntegration({
222
provider: "custom", // Your provider name
223
autoCapture: false, // Manual flag tracking
224
}),
225
],
226
});
227
228
// Manual feature flag tracking
229
function evaluateFeatureFlag(flagKey: string, userId: string, defaultValue: boolean): boolean {
230
const result = yourCustomFlagProvider.evaluate(flagKey, userId, defaultValue);
231
232
// Manually track feature flag evaluation
233
Sentry.setContext("feature_flags", {
234
[flagKey]: {
235
value: result,
236
userId,
237
provider: "custom",
238
timestamp: Date.now(),
239
},
240
});
241
242
return result;
243
}
244
245
// Usage
246
const showFeature = evaluateFeatureFlag("show_new_feature", "user-123", false);
247
```
248
249
## Types
250
251
### Integration Options
252
253
```typescript { .api }
254
interface LaunchDarklyOptions {
255
/** Include flag keys and values in context */
256
captureFlags?: boolean;
257
/** Include variation details in spans */
258
captureVariations?: boolean;
259
/** Maximum number of flags to capture per evaluation */
260
maxFlags?: number;
261
}
262
263
interface OpenFeatureOptions {
264
/** Include flag keys and values in context */
265
captureFlags?: boolean;
266
/** Include provider information in context */
267
captureProviderInfo?: boolean;
268
/** Maximum number of flags to capture per evaluation */
269
maxFlags?: number;
270
}
271
272
interface StatsigOptions {
273
/** Include feature gate evaluations */
274
captureGates?: boolean;
275
/** Include dynamic config evaluations */
276
captureConfigs?: boolean;
277
/** Include experiment assignments */
278
captureExperiments?: boolean;
279
/** Maximum number of evaluations to capture */
280
maxEvaluations?: number;
281
}
282
283
interface UnleashOptions {
284
/** Include toggle evaluations */
285
captureToggles?: boolean;
286
/** Include variant selections */
287
captureVariants?: boolean;
288
/** Maximum number of toggles to capture per evaluation */
289
maxToggles?: number;
290
}
291
292
interface FeatureFlagsOptions {
293
/** Provider name for identification */
294
provider?: string;
295
/** Automatically capture flag evaluations */
296
autoCapture?: boolean;
297
/** Custom flag evaluation handler */
298
onFlagEvaluated?: (flagData: FlagEvaluationData) => void;
299
}
300
301
interface FlagEvaluationData {
302
/** Flag key/name */
303
key: string;
304
/** Evaluated value */
305
value: any;
306
/** User context */
307
user?: any;
308
/** Provider name */
309
provider?: string;
310
/** Evaluation timestamp */
311
timestamp?: number;
312
/** Additional metadata */
313
metadata?: Record<string, any>;
314
}
315
316
type FlagUsedHandler = (flagKey: string, value: any, variationDetail?: any) => void;
317
```