Set Up Feature Flags

With Feature Flags, Sentry tracks feature flag evaluations in your application, keeps an audit log of feature flag changes, and reports any suspicious updates that may have caused an error.

If you use a third-party SDK to evaluate feature flags, you can enable a Sentry SDK integration to track those evaluations. Integrations are provider specific. Documentation for supported SDKs is listed below.

If you use an unsupported solution, use the generic API to manually track feature flag evaluations. The SDK stores each evaluation on the current scope. If a span or transaction is active, the SDK also records the evaluation on that active span or transaction. Only boolean flag evaluations are supported.

Copied
import io.sentry.Sentry;

Sentry.addFeatureFlag("test-flag", false);
Sentry.captureException(new Exception("Something went wrong!"));

Go to your Sentry project and confirm that your error event has recorded the feature flag "test-flag" and its value "false".

If you use a separate IScopes instance, add the feature flag evaluation to that instance. This updates its scope and active span or transaction, without changing the global Sentry scope:

Copied
scopes.addFeatureFlag("test-flag", false);
scopes.captureException(new Exception("Something went wrong!"));

Use a scope callback when the evaluation should apply to this capture's local scope instead of remaining on the current scope:

Copied
import io.sentry.Sentry;

Sentry.captureException(new Exception("Something went wrong!"), scope -> {
scope.addFeatureFlag("test-flag", false);
});

Feature flags added in a scope callback don't persist on the current scope. If a span or transaction is active, the SDK still records the evaluation on that active span or transaction.

Clear feature flags when they no longer apply, such as after a user signs out or switches accounts:

Copied
import io.sentry.Sentry;

Sentry.configureScope(scope -> {
scope.clearFeatureFlags();
});

clearFeatureFlags() removes evaluations only from the current scope. It doesn't affect parent or sibling scopes, or evaluations already recorded on an active span or transaction.

Scope evaluations are attached to error and message events. By default, the current scope keeps the latest evaluation for up to 100 flag names. Re-evaluating a flag updates its stored value and makes it the most recent evaluation. When a scope forks, the child receives a copy of these evaluations, and changes to the copy don't affect the parent scope.

Active spans and transactions record evaluations for up to 10 flag names as span attributes using the flag.evaluation.<name> key. Re-evaluating a recorded flag updates its value. After 10 flag names are recorded, evaluations for new flag names are ignored. Spans don't inherit evaluations from their parent span.

Change tracking requires registering a Sentry webhook with a feature flag provider. For set up instructions, visit the documentation for your provider:

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").