Skip to content

Commit fe943f6

Browse files
committed
feat(flags): document python UnleashIntegration
1 parent 24d04c3 commit fe943f6

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Unleash
3+
description: "Learn how to use Sentry with Unleash."
4+
---
5+
6+
<PlatformContent includePath="feature-flags/prerelease-alert" />
7+
8+
The [Unleash](https://www.getunleash.io/) integration tracks feature flag evaluations produced by the Unleash SDK. These evaluations are held in memory and sent to Sentry for review and analysis if an error occurs. **At the moment, we only support boolean flag evaluations.**
9+
10+
## Install
11+
12+
Install `sentry-sdk` and `UnleashClient` from PyPI. The minimum versions to use this integration are TODO: and 6.0.1, respectively.
13+
14+
```bash
15+
pip install --upgrade sentry-sdk UnleashClient
16+
```
17+
18+
## Configure
19+
20+
Add a `UnleashIntegration` to your `integrations` list:
21+
22+
```python
23+
import sentry_sdk
24+
from sentry_sdk.integrations.unleash import UnleashIntegration
25+
from UnleashClient import UnleashClient
26+
27+
unleash_client = UnleashClient(
28+
url="<Unleash server URL>/api/", # "http://localhost:4242/api/" if you are self-hosting Unleash.
29+
app_name="my-app", # Identifies your app in the Unleash UI.
30+
custom_headers={"Authorization": os.environ["UNLEASH_CLIENT_API_TOKEN"]}
31+
)
32+
33+
unleash_integration = UnleashIntegration(unleash_client)
34+
35+
sentry_sdk.init(
36+
dsn="___PUBLIC_DSN___",
37+
integrations=[
38+
unleash_integration,
39+
],
40+
)
41+
```
42+
43+
For more information on how to use Unleash, read Unleash's [Python reference](https://docs.getunleash.io/reference/sdks/python) and [quickstart guide](https://docs.getunleash.io/quickstart).
44+
45+
## Verify
46+
47+
The integration is tested by evaluating a feature flag using your Unleash SDK before capturing an exception.
48+
49+
```python
50+
import sentry_sdk
51+
52+
# Re-use `unleash_client` from the previous step.
53+
test_flag_enabled = unleash_client.is_enabled("test-flag")
54+
55+
sentry_sdk.capture_exception(Exception("Something went wrong!"))
56+
```
57+
58+
Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag" and its value
59+
is equal to `test_flag_enabled`. Note we also track the `"enabled"` field in the result of [`get_variant()`](https://docs.getunleash.io/reference/sdks/python#getting-a-variant).
60+
61+
<PlatformContent includePath="feature-flags/next-steps" />

0 commit comments

Comments
 (0)