Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(flags): document custom featureFlagsIntegration and refactor all JS integration docs #12151

Merged
merged 12 commits into from
Dec 18, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: FeatureFlags
description: "Learn how to attach custom feature flag data to Sentry error events."
notSupported:
- javascript.aws-lambda
- javascript.azure-functions
- javascript.bun
- javascript.capacitor
- javascript.cloudflare
- javascript.connect
- javascript.cordova
- javascript.deno
- javascript.electron
- javascript.express
- javascript.fastify
- javascript.gcp-functions
- javascript.hapi
- javascript.koa
- javascript.nestjs
- javascript.nodejs
- javascript.wasm
---

<PlatformContent includePath="feature-flags/prerelease-alert" />

<Alert level="info">

This integration only works inside a browser environment. If you are using a specific
feature flag provider, refer to the supported list [here](/platforms/javascript/feature-flags/#enable-evaluation-tracking) before setting up this integration.

</Alert>

The Feature Flags integration allows you to manually track feature flag evaluations through an API. These evaluations are held in memory and sent to Sentry when an error occurs.
**At the moment, we only support boolean flag evaluations.**

_Import names: `Sentry.featureFlagsIntegration` and `type Sentry.FeatureFlagsIntegration`_

## Install

Install your platform's Sentry SDK from npm.

## Configure

```JavaScript
import * as Sentry from '@sentry/browser';

Sentry.init({
dsn: "___PUBLIC_DSN___",
integrations: [Sentry.featureFlagsIntegration()]
});
```

## Verify

The integration is tested by calling the `addFeatureFlag` method before capturing an exception.

```JavaScript
import * as Sentry from '@sentry/browser';

const flagsIntegration = Sentry.getClient()?.getIntegrationByName<Sentry.FeatureFlagsIntegration>('FeatureFlags');
if (flagsIntegration) {
flagsIntegration.addFeatureFlag('hello', false);
} else {
// check your configure step
}
Sentry.captureException(new Error('broke'));
```

Visit the Sentry website and confirm that your error event has recorded the feature flag "hello" and its value "false".

<PlatformContent includePath="feature-flags/next-steps" />
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import * as LaunchDarkly from 'launchdarkly-js-client-sdk';
// You may have to wait for your client to initialize before doing this.
ldClient?.variation("hello", false);

Sentry.captureException(Exception("Something went wrong!"))
Sentry.captureException(new Error("Something went wrong!"))
```

Visit the Sentry website and confirm that your error event has recorded the feature flag "hello" and its value "false".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { OpenFeature } from '@openfeature/web-sdk';
const client = OpenFeature.getClient();
const result = client.getBooleanValue('hello', false);

Sentry.captureException(Exception("Something went wrong!"))
Sentry.captureException(new Error("Something went wrong!"))
```

Visit the Sentry website and confirm that your error event has recorded the feature flag "hello" and its value "false".
Expand Down
2 changes: 2 additions & 0 deletions docs/platforms/javascript/common/feature-flags/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ Evaluation tracking requires enabling an SDK integration. Integrations are provi
- [OpenFeature](/platforms/javascript/configuration/integrations/openfeature/)
- [LaunchDarkly](/platforms/javascript/configuration/integrations/launchdarkly/)

To manually track evaluations through an API, see the custom [FeatureFlags](/platforms/javascript/configuration/integrations/featureflags/) integration.

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