Skip to content

Commit 415d790

Browse files
authored
flags: Add improved developer documentation (#12643)
* Add improved developer documentation * Remove mention of cap * Add period
1 parent 1fb365c commit 415d790

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

develop-docs/sdk/expected-features/data-handling.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ Fields in the event payload that allow user-specified or dynamic values are rest
111111

112112
- Mappings of values (such as HTTP data, extra data, etc) are limited to 50 item pairs.
113113
- Event IDs are limited to 36 characters and must be valid UUIDs.
114+
- Flag keys are limited to 32 characters.
115+
- Flag values are limited to 200 characters.
114116
- Tag keys are limited to 32 characters.
115117
- Tag values are limited to 200 characters.
116118
- Culprits are limited to 200 characters.

develop-docs/sdk/expected-features/index.mdx

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ What scope means depends on the application, for a web framework it is most like
3030

3131
## Automatic Context Data
3232

33-
Automatic addition of useful attributes such as `tags` or `extra` or specific `contexts`. Typically means the SDK hooks into a framework so that it can set attributes that are known to be useful for most users. Please check [Data Handling](/sdk/expected-features/data-handling) for considerations.
33+
Automatic addition of useful attributes such as `flags` or `tags` or `extra` or specific `contexts`. Typically means the SDK hooks into a framework so that it can set attributes that are known to be useful for most users. Please check [Data Handling](/sdk/expected-features/data-handling) for considerations.
3434

3535
## Breadcrumbs
3636

@@ -118,24 +118,15 @@ This functionality should be gated behind the `includeLocalVariables` option, wh
118118

119119
## Feature Flags
120120

121-
An SDK may expose a Scope property for tracking feature flag evaluations. When the scope forks, it's important to clone the feature flags property. Leaking flag evaluations between threads could lead to inaccurate feature flag evaluation logs.
121+
An SDK may optionally support feature flag collection. Feature flags are collected on evaluation, stored on the scope, and submitted to Sentry on error obeying the schema specified in the <Link to="/sdk/data-model/event-payloads/contexts/#feature-flag-context">Feature Flag Context</Link> protocol documentation.
122122

123-
The Scope's flag property should have a capped capacity and should prefer recently-evaluated flags over less-recently-evaluated flags. The recommended data structure is a LRU-cache but it is not required so long as the data structure behaves similarly. Serious deviations from the behavior of an LRU-cache should be documented for your language.
123+
If an SDK supports feature flags it must expose a function `set_flag` which has identical behavior to the `set_tag` function. It must accept a key of type string and a value which is a union of string, boolean, integer, float, and structure. An SDK may hold up to 100 evaluations. Evaluations are ordered based on their evaluation time. Typically, an LRU cache is used to store feature flags. When the capacity of the cache is exceeded the oldest flag is dropped. Any (or multiple) data structure(s) may be chosen by the SDK to store feature flags as long as the evaluation order of the flags is maintained.
124124

125-
The Scope's flag property should expose two methods: `get/0` and `set/2`. `set/2` takes two arguments. The first argument is the name of the flag. It is of type string. The second argument is the evaluation result. It is of type boolean. `set/2` should remove all entries from the LRU-cache which match the provided flag's name and append the new evaluation result to the end of the queue. `get/0` accepts zero arguments. The `get/0` method must return a list of serialized flag evaluation results in order of evaluation. Oldest values first, newest values last. See the <Link to="/sdk/data-model/event-payloads/contexts/#feature-flag-context">Feature Flag Context</Link> protocol documentation for details.
125+
Because flags are stored on the scope, when a scope forks the flags data structure must be cloned. Failure to clone the data structure appropriately will lead to flags leaking across thread boundaries and lead to unexpected results.
126126

127127
### Integrations
128128

129-
Integrations automate the work of tracking feature flag evaluations and serializing them on error context. An integration should hook into third-party SDK and record feature flag evaluations using the current scope. For example, in Python an integration would call `sentry_sdk.get_current_scope().flags.set(...)` on each flag evaluation.
130-
131-
An integration is also responsible for registering an "on error" hook with the Sentry SDK. When an error occurs the integration should request the current scope and serialize the flags property. For example, in Python an integration might define this callback function:
132-
133-
```python
134-
def flag_error_processor(event, exc_info):
135-
scope = sentry_sdk.get_current_scope()
136-
event["contexts"]["flags"] = {"values": scope.flags.get()}
137-
return event
138-
```
129+
Integrations automate the work of tracking feature flag evaluations. An integration should hook into a third-party SDK and record feature flag evaluations using the current scope.
139130

140131
## Desymbolication
141132

develop-docs/sdk/miscellaneous/hub_and_scope_refactoring.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ This scope is probably only used for process-wide data like the `release`.
7878

7979
**Isolation Scope**
8080

81-
This scope holds data only applicable to the current request (on a server), tab (in a browser), or user (on a mobile). The top-level APIs that manipulate data (like `sentry_sdk.set_tag()`, `sentry_sdk.set_context()` etc) write to the isolation scope (at least once the migration phase is over, see "Backwards Compatibility").
81+
This scope holds data only applicable to the current request (on a server), tab (in a browser), or user (on a mobile). The top-level APIs that manipulate data (like `sentry_sdk.set_flag()`, `sentry_sdk.set_tag()`, `sentry_sdk.set_context()` etc.) write to the isolation scope (at least once the migration phase is over, see "Backwards Compatibility").
8282

8383
The isolation scope is stored in a context variable, thread local, async local, or something similar (depending on the platform). It may also be stored on OTel `Context` so we can rely on OTels `Context` propagation once SDKs implement POTEL.
8484

develop-docs/sdk/miscellaneous/unified-api/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ Sentry.configureScope((scope) =>
216216

217217
- `scope.set_extras(extras)`: Sets an object with key/value pairs, convenience function instead of multiple `set_extra` calls. As with `set_extra` this is considered deprecated functionality.
218218

219+
- `scope.set_flag(key, value)`: Sets the flag to a string value, overwriting a potential previous value. Entries can not be removed except by expiration.
220+
219221
- `scope.set_tag(key, value)`: Sets the tag to a string value, overwriting a potential previous value. Removing a key is SDK-defined, either with a `remove_tag` function or by passing nothing as data.
220222

221223
- `scope.set_tags(tags)`: Sets an object with key/value pairs, convenience function instead of multiple `set_tag` calls.

0 commit comments

Comments
 (0)