Skip to content

Commit 41d352e

Browse files
aliu39billyvg
andauthored
feat(flags): document custom featureFlagsIntegration and refactor all JS integration docs (#12151)
* feat(flags): document featureFlagsIntegration for custom flag tracking * Lowercase filename and create python file * Del python doc * review comment Co-authored-by: Billy Vong <[email protected]> * keep title consistent w identifier * Rename featureFlags.mdx to featureflags.mdx * Keep sentry/browser in code snippet * Link from js index * Link index from integration doc * Fix invalid Exception syntax * ref(flags): add platform-specific content and refactor JS integration docs (#12172) * ref(flags): add platform-specific content to JS integration docs * featureflags platforms * ld and of platforms * Rm 'Install with npm or yarn' * Label featureflags code as TypeScript * Update info alert and ffs link * Lowercase all code snippet language headers * Rewording from review * Use single quotes in all code snippets * Update provider pkg and docs links * Update links, name 'Generic Support' --------- Co-authored-by: Billy Vong <[email protected]>
1 parent 09f3ae0 commit 41d352e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1092
-84
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: FeatureFlags
3+
description: "Learn how to attach custom feature flag data to Sentry error events."
4+
notSupported:
5+
- javascript.aws-lambda
6+
- javascript.azure-functions
7+
- javascript.bun
8+
- javascript.capacitor
9+
- javascript.cloudflare
10+
- javascript.connect
11+
- javascript.cordova
12+
- javascript.deno
13+
- javascript.electron
14+
- javascript.express
15+
- javascript.fastify
16+
- javascript.gcp-functions
17+
- javascript.hapi
18+
- javascript.koa
19+
- javascript.nestjs
20+
- javascript.nodejs
21+
- javascript.wasm
22+
---
23+
24+
<PlatformContent includePath="feature-flags/prerelease-alert" />
25+
26+
<Alert level="info">
27+
28+
This integration only works inside a browser environment. It is only available from a package-based install (e.g. `npm` or `yarn`).
29+
30+
</Alert>
31+
32+
<Alert level ="info">
33+
34+
If you are using an external feature flag provider, refer to the [supported list](/platforms/javascript/feature-flags/#enable-evaluation-tracking) before setting up this integration.
35+
36+
</Alert>
37+
38+
The Feature Flags integration allows you to manually track feature flag evaluations through an API.
39+
These evaluations are held in memory and sent to Sentry when an error occurs.
40+
**At the moment, we only support boolean flag evaluations.**
41+
42+
_Import names: `Sentry.featureFlagsIntegration` and `type Sentry.FeatureFlagsIntegration`_
43+
44+
<PlatformContent includePath="/configuration/featureflags" />
45+
46+
Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag" and its value "false".
47+
48+
<PlatformContent includePath="feature-flags/next-steps" />

docs/platforms/javascript/common/configuration/integrations/launchdarkly.mdx

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,16 @@ notSupported:
2525

2626
<Alert level="info">
2727

28-
This integration only works inside a browser environment.
28+
This integration only works inside a browser environment. It is only available from a package-based install (e.g. `npm` or `yarn`).
2929

3030
</Alert>
3131

3232
The [LaunchDarkly](https://launchdarkly.com/) integration tracks feature flag evaluations produced by the LaunchDarkly SDK. These evaluations are held in memory, and in the event an error occurs, sent to Sentry for review and analysis. **At the moment, we only support boolean flag evaluations.**
3333

3434
_Import names: `Sentry.launchDarklyIntegration` and `Sentry.buildLaunchDarklyFlagUsedHandler`_
3535

36-
## Install
36+
<PlatformContent includePath="/configuration/launchdarkly" />
3737

38-
Install your platform's Sentry SDK and [`launchdarkly-js-client-sdk`](https://www.npmjs.com/package/launchdarkly-js-client-sdk) from npm.
39-
40-
## Configure
41-
42-
```JavaScript
43-
import * as Sentry from '@sentry/browser';
44-
import * as LaunchDarkly from 'launchdarkly-js-client-sdk';
45-
46-
Sentry.init({
47-
dsn: "___PUBLIC_DSN___",
48-
integrations: [Sentry.launchDarklyIntegration()]
49-
});
50-
51-
const ldClient = LaunchDarkly.initialize(
52-
'my-client-ID',
53-
{kind: 'user', key: 'my-user-context-key'},
54-
{inspectors: [Sentry.buildLaunchDarklyFlagUsedHandler()]}
55-
);
56-
```
57-
58-
Learn more about the [LaunchDarkly SDK](https://docs.launchdarkly.com/sdk/client-side/javascript). At the moment, **we aren't officially supporting framework-specific LaunchDarkly SDKs.** However, you may reuse the setup code for [React](https://www.npmjs.com/package/launchdarkly-react-client-sdk) and [client-side Node.js](https://www.npmjs.com/package/launchdarkly-node-client-sdk).
59-
60-
## Verify
61-
62-
The integration is tested by evaluating a feature flag with your LaunchDarkly SDK before capturing an exception.
63-
64-
```JavaScript
65-
import * as Sentry from '@sentry/browser';
66-
import * as LaunchDarkly from 'launchdarkly-js-client-sdk';
67-
68-
// Evaluate a flag with a default value, with the ldClient from the Configure step.
69-
// You may have to wait for your client to initialize before doing this.
70-
ldClient?.variation("hello", false);
71-
72-
Sentry.captureException(Exception("Something went wrong!"))
73-
```
74-
75-
Visit the Sentry website and confirm that your error event has recorded the feature flag "hello" and its value "false".
38+
Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag" and its value "false".
7639

7740
<PlatformContent includePath="feature-flags/next-steps" />

docs/platforms/javascript/common/configuration/integrations/openfeature.mdx

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,57 +25,16 @@ notSupported:
2525

2626
<Alert level="info">
2727

28-
This integration only works inside a browser environment.
28+
This integration only works inside a browser environment. It is only available from a package-based install (e.g. `npm` or `yarn`).
2929

3030
</Alert>
3131

3232
The [OpenFeature](https://openfeature.dev/) integration tracks feature flag evaluations produced by the OpenFeature SDK. These evaluations are held in memory, and in the event an error occurs, sent to Sentry for review and analysis. **At the moment, we only support boolean flag evaluations.**
3333

3434
_Import name: `Sentry.openFeatureIntegration` and `Sentry.OpenFeatureIntegrationHook`_
3535

36-
## Install
36+
<PlatformContent includePath="/configuration/openfeature" />
3737

38-
Install your platform's Sentry SDK and [`@openfeature/web-sdk`](https://www.npmjs.com/package/@openfeature/web-sdk) from npm.
39-
40-
## Configure
41-
42-
```JavaScript
43-
import * as Sentry from '@sentry/browser';
44-
import { OpenFeature } from '@openfeature/web-sdk';
45-
46-
Sentry.init({
47-
dsn: "___PUBLIC_DSN___",
48-
integrations: [Sentry.openFeatureIntegration()]
49-
});
50-
51-
OpenFeature.setProvider(new MyProviderOfChoice());
52-
53-
// Option 1: track all OpenFeature evaluations.
54-
OpenFeature.addHooks(new Sentry.OpenFeatureIntegrationHook());
55-
56-
// Option 2: only track evaluations by a specific client.
57-
const client = OpenFeature.getClient();
58-
client.addHooks(new Sentry.OpenFeatureIntegrationHook());
59-
```
60-
61-
Learn more about OpenFeature [providers](https://openfeature.dev/docs/reference/concepts/provider) and the [web SDK](https://openfeature.dev/docs/reference/technologies/client/web/).
62-
63-
## Verify
64-
65-
The integration is tested by evaluating a feature flag with your OpenFeature SDK before capturing an exception.
66-
67-
```JavaScript
68-
import * as Sentry from '@sentry/browser';
69-
import { OpenFeature } from '@openfeature/web-sdk';
70-
71-
// Evaluate a flag with a default value. If you added the hook to a client in
72-
// the Configure step, make sure to use the same client here.
73-
const client = OpenFeature.getClient();
74-
const result = client.getBooleanValue('hello', false);
75-
76-
Sentry.captureException(Exception("Something went wrong!"))
77-
```
78-
79-
Visit the Sentry website and confirm that your error event has recorded the feature flag "hello" and its value "false".
38+
Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag" and its value "false".
8039

8140
<PlatformContent includePath="feature-flags/next-steps" />

docs/platforms/javascript/common/feature-flags/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ description: With Feature Flags, Sentry tracks feature flag evaluations in your
3333
Evaluation tracking requires enabling an SDK integration. Integrations are provider specific. Documentation for supported providers is listed below.
3434
- [OpenFeature](/platforms/javascript/configuration/integrations/openfeature/)
3535
- [LaunchDarkly](/platforms/javascript/configuration/integrations/launchdarkly/)
36+
- [Generic Support](/platforms/javascript/configuration/integrations/featureflags/) - if you use an unsupported or in-house provider, you may manually track evaluations through an API.
3637

3738
<PlatformContent includePath="feature-flags/enable-change-tracking" />

docs/platforms/python/feature-flags/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ Evaluation tracking requires enabling an SDK integration. Integrations are provi
1616

1717
- [OpenFeature](/platforms/python/integrations/openfeature/)
1818
- [LaunchDarkly](/platforms/python/integrations/launchdarkly/)
19+
- [Generic Support](/platforms/javascript/configuration/integrations/featureflags/) - if you use an unsupported or in-house provider, you may manually track evaluations through an API.
1920

2021
<PlatformContent includePath="feature-flags/enable-change-tracking" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```typescript
2+
import * as Sentry from '@sentry/angular';
3+
4+
Sentry.init({
5+
dsn: '___PUBLIC_DSN___',
6+
integrations: [Sentry.featureFlagsIntegration()]
7+
});
8+
9+
const flagsIntegration = Sentry.getClient()?
10+
.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags');
11+
if (flagsIntegration) {
12+
flagsIntegration.addFeatureFlag('test-flag', false);
13+
} else {
14+
// Something went wrong, check your DSN and/or integrations
15+
}
16+
Sentry.captureException(new Error('Something went wrong!'));
17+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```typescript
2+
import * as Sentry from '@sentry/astro';
3+
4+
Sentry.init({
5+
dsn: '___PUBLIC_DSN___',
6+
integrations: [Sentry.featureFlagsIntegration()]
7+
});
8+
9+
const flagsIntegration = Sentry.getClient()?
10+
.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags');
11+
if (flagsIntegration) {
12+
flagsIntegration.addFeatureFlag('test-flag', false);
13+
} else {
14+
// Something went wrong, check your DSN and/or integrations
15+
}
16+
Sentry.captureException(new Error('Something went wrong!'));
17+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```typescript
2+
import * as Sentry from '@sentry/ember';
3+
4+
Sentry.init({
5+
dsn: '___PUBLIC_DSN___',
6+
integrations: [Sentry.featureFlagsIntegration()]
7+
});
8+
9+
const flagsIntegration = Sentry.getClient()?
10+
.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags');
11+
if (flagsIntegration) {
12+
flagsIntegration.addFeatureFlag('test-flag', false);
13+
} else {
14+
// Something went wrong, check your DSN and/or integrations
15+
}
16+
Sentry.captureException(new Error('Something went wrong!'));
17+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```typescript
2+
import * as Sentry from '@sentry/gatsby';
3+
4+
Sentry.init({
5+
dsn: '___PUBLIC_DSN___',
6+
integrations: [Sentry.featureFlagsIntegration()]
7+
});
8+
9+
const flagsIntegration = Sentry.getClient()?
10+
.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags');
11+
if (flagsIntegration) {
12+
flagsIntegration.addFeatureFlag('test-flag', false);
13+
} else {
14+
// Something went wrong, check your DSN and/or integrations
15+
}
16+
Sentry.captureException(new Error('Something went wrong!'));
17+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
```typescript
2+
import * as Sentry from '@sentry/browser';
3+
4+
Sentry.init({
5+
dsn: '___PUBLIC_DSN___',
6+
integrations: [Sentry.featureFlagsIntegration()]
7+
});
8+
9+
const flagsIntegration = Sentry.getClient()?
10+
.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags');
11+
if (flagsIntegration) {
12+
flagsIntegration.addFeatureFlag('test-flag', false);
13+
} else {
14+
// Something went wrong, check your DSN and/or integrations
15+
}
16+
Sentry.captureException(new Error('Something went wrong!'));
17+
```

0 commit comments

Comments
 (0)