-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(feature-flags): Document Apple, Java, and Android APIs #18755
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
Open
denrase
wants to merge
2
commits into
master
Choose a base branch
from
denrase/cocoa-feature-flags
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| title: Set Up Feature Flags | ||
| sidebar_title: Feature Flags | ||
| sidebar_order: 5750 | ||
| sidebar_section: features | ||
| 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. | ||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - You have version 9.22.0 or later of the <PlatformLink to="/">Apple SDK installed</PlatformLink>. | ||
|
|
||
| ## Enable Evaluation Tracking | ||
|
|
||
| <PlatformContent includePath="feature-flags/evaluation-tracking-index" /> | ||
|
|
||
| ## Enable Change Tracking | ||
|
|
||
| <PlatformContent includePath="feature-flags/change-tracking-index" /> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,23 +3,83 @@ If you use a third-party SDK to evaluate feature flags, you can enable a Sentry | |
| - <PlatformLink to="/integrations/launchdarkly">LaunchDarkly</PlatformLink> | ||
|
|
||
| ### Generic API | ||
| If you use an unsupported solution, you can use the generic API to manually track feature flag evaluations. These evaluations are held in memory and are sent to Sentry on error and transaction events. **At the moment, we only support boolean flag evaluations.** | ||
|
|
||
| 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 {3} | ||
| import io.sentry.Sentry; | ||
|
|
||
| Sentry.addFeatureFlag("feature_flag.test-flag", false); | ||
| Sentry.addFeatureFlag("test-flag", false); | ||
| Sentry.captureException(new Exception("Something went wrong!")); | ||
| ``` | ||
|
|
||
| ```kotlin {3} | ||
| import io.sentry.Sentry | ||
|
|
||
| Sentry.addFeatureFlag("feature_flag.test-flag", false) | ||
| Sentry.addFeatureFlag("test-flag", false) | ||
| Sentry.captureException(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". | ||
|
|
||
| ### 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 {1} | ||
| scopes.addFeatureFlag("test-flag", false); | ||
| scopes.captureException(new Exception("Something went wrong!")); | ||
| ``` | ||
|
|
||
| ```kotlin {1} | ||
| scopes.addFeatureFlag("test-flag", false) | ||
| scopes.captureException(Exception("Something went wrong!")) | ||
| ``` | ||
|
|
||
| ### 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 {4} | ||
| import io.sentry.Sentry; | ||
|
|
||
| Sentry.captureException(new Exception("Something went wrong!"), scope -> { | ||
| scope.addFeatureFlag("test-flag", false); | ||
| }); | ||
| ``` | ||
|
|
||
| ```kotlin {4} | ||
| import io.sentry.Sentry | ||
|
|
||
| Sentry.captureException(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 | ||
|
|
||
| Clear feature flags when they no longer apply, such as after a user signs out or switches accounts: | ||
|
|
||
| ```java {4} | ||
| import io.sentry.Sentry; | ||
|
|
||
| Sentry.configureScope(scope -> { | ||
| scope.clearFeatureFlags(); | ||
| }); | ||
| ``` | ||
|
|
||
| ```kotlin {4} | ||
| 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 events. By default, the current scope keeps the 100 most recent, unique feature flag evaluations. When a scope forks, the child receives a copy of these evaluations, and changes to the copy don't affect the parent scope. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| Active spans and transactions record the first 10 unique feature flags as span attributes using the `flag.evaluation.<name>` key. Spans don't inherit evaluations from their parent span. | ||
|
Comment on lines
+83
to
+85
|
||
75 changes: 75 additions & 0 deletions
75
platform-includes/feature-flags/evaluation-tracking-index/apple.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| 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 | ||
|
|
||
| Call `SentrySDK.addFeatureFlag` after evaluating a feature flag: | ||
|
|
||
| ```swift {tabTitle:Swift} {mdExpandTabs} | ||
| import Sentry | ||
|
|
||
| SentrySDK.addFeatureFlag(name: "test-flag", result: false) | ||
| SentrySDK.capture(error: error) | ||
| ``` | ||
|
|
||
| ```objc {tabTitle:Objective-C (SentryObjC)} | ||
| #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 | ||
|
|
||
| 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 {tabTitle:Swift} {mdExpandTabs} | ||
| hub.addFeatureFlag(name: "test-flag", result: false) | ||
| hub.capture(error: error) | ||
| ``` | ||
|
|
||
| ```objc {tabTitle:Objective-C (SentryObjC)} | ||
| [hub addFeatureFlagWithName:@"test-flag" result:NO]; | ||
| [hub captureError:error]; | ||
| ``` | ||
|
|
||
| ### 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 {tabTitle:Swift} {mdExpandTabs} | ||
| SentrySDK.capture(error: error) { scope in | ||
| scope.addFeatureFlag(name: "test-flag", result: false) | ||
| } | ||
| ``` | ||
|
|
||
| ```objc {tabTitle:Objective-C (SentryObjC)} | ||
| [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 | ||
|
|
||
| Clear feature flags when they no longer apply, such as after a user signs out or switches accounts: | ||
|
|
||
| ```swift {tabTitle:Swift} {mdExpandTabs} | ||
| SentrySDK.configureScope { scope in | ||
| scope.clearFeatureFlags() | ||
| } | ||
| ``` | ||
|
|
||
| ```objc {tabTitle:Objective-C (SentryObjC)} | ||
| [SentryObjCSDK configureScope:^(SentryObjCScope * _Nonnull 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. The current scope keeps the 100 most recent, unique feature flag evaluations. 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 the first 10 unique feature flags as span attributes using the `flag.evaluation.<name>` key. Spans don't inherit evaluations from their parent span. | ||
|
Comment on lines
+73
to
+75
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Should we assign a label "New" to this page in the menu bar?