---
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/apple/guides/tvos/feature-flags/
---

# Set Up Feature Flags | Sentry for tvOS

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

* You have version 9.22.0 or later of the [Apple SDK installed](https://docs.sentry.io/platforms/apple/guides/tvos.md).

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

If you use a third-party SDK to evaluate feature flags, 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.

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

Call `SentrySDK.addFeatureFlag` after evaluating a feature flag:

**Swift**

```swift
import Sentry

SentrySDK.addFeatureFlag(name: "test-flag", result: false)
SentrySDK.capture(error: error)
```

**Objective-C (SentryObjC)**

```objc
#import <SentryObjC/SentryObjC.h>

[SentryObjCSDK addFeatureFlagWithName:@"test-flag" result:NO];
[SentryObjCSDK captureError:error];
```

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

### [Custom Hub](https://docs.sentry.io/platforms/apple/guides/tvos/feature-flags.md#custom-hub)

If you use a custom hub, add the feature flag evaluation to that hub. This updates the custom hub's scope and active span or transaction, without changing the global `SentrySDK` scope:

**Swift**

```swift
hub.addFeatureFlag(name: "test-flag", result: false)
hub.capture(error: error)
```

**Objective-C (SentryObjC)**

```objc
[hub addFeatureFlagWithName:@"test-flag" result:NO];
[hub captureError:error];
```

### [Scope Callback](https://docs.sentry.io/platforms/apple/guides/tvos/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:

**Swift**

```swift
SentrySDK.capture(error: error) { scope in
    scope.addFeatureFlag(name: "test-flag", result: false)
}
```

**Objective-C (SentryObjC)**

```objc
[SentryObjCSDK captureError:error withScopeBlock:^(SentryObjCScope * _Nonnull scope) {
    [scope addFeatureFlagWithName:@"test-flag" result:NO];
}];
```

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/apple/guides/tvos/feature-flags.md#clear-feature-flags)

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

**Swift**

```swift
SentrySDK.configureScope { scope in
    scope.clearFeatureFlags()
}
```

**Objective-C (SentryObjC)**

```objc
[SentryObjCSDK configureScope:^(SentryObjCScope * _Nonnull scope) {
    [scope clearFeatureFlags];
}];
```

`clearFeatureFlags()` removes evaluations from the current scope. It doesn't remove evaluations already recorded on an active span or transaction.

Scope evaluations are attached to error and message events. 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.

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/apple/guides/tvos/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)
