---
title: "Feature Flags"
description: "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."
url: https://docs.sentry.io/platforms/java/guides/servlet/feature-flags/
---

# Set Up Feature Flags | Sentry for Servlet

## [Prerequisites](https://docs.sentry.io/platforms/java/guides/servlet/feature-flags.md#prerequisites)

* You have version 8.42.0 or later of the [Java SDK installed](https://docs.sentry.io/platforms/java/guides/servlet.md).

## [Enable Evaluation Tracking](https://docs.sentry.io/platforms/java/guides/servlet/feature-flags.md#enable-evaluation-tracking)

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.

* [OpenFeature](https://docs.sentry.io/platforms/java/guides/servlet/integrations/openfeature.md)
* [LaunchDarkly](https://docs.sentry.io/platforms/java/guides/servlet/integrations/launchdarkly.md)

### [Generic API](https://docs.sentry.io/platforms/java/guides/servlet/feature-flags.md#generic-api)

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.

```java
import io.sentry.Sentry;

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

*Other available variations of the above snippet: kotlin*

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

### [Custom Scopes](https://docs.sentry.io/platforms/java/guides/servlet/feature-flags.md#custom-scopes)

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:

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

*Other available variations of the above snippet: kotlin*

### [Scope Callback](https://docs.sentry.io/platforms/java/guides/servlet/feature-flags.md#scope-callback)

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

```java
import io.sentry.Sentry;

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

*Other available variations of the above snippet: kotlin*

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](https://docs.sentry.io/platforms/java/guides/servlet/feature-flags.md#clear-feature-flags)

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

```java
import io.sentry.Sentry;

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

*Other available variations of the above snippet: kotlin*

`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.

## [Enable Change Tracking](https://docs.sentry.io/platforms/java/guides/servlet/feature-flags.md#enable-change-tracking)

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

* [Flagsmith](https://docs.sentry.io/integrations/feature-flag/flagsmith.md#change-tracking)
* [LaunchDarkly](https://docs.sentry.io/integrations/feature-flag/launchdarkly.md#change-tracking)
* [Statsig](https://docs.sentry.io/integrations/feature-flag/statsig.md#change-tracking)
* [Unleash](https://docs.sentry.io/integrations/feature-flag/unleash.md#change-tracking)
* [Generic](https://docs.sentry.io/integrations/feature-flag/generic.md#change-tracking)
