Skip to content

Commit 049b5e8

Browse files
aliu39antonpirker
andauthored
feat(flags): document statsig python integration (#12722)
--------- Co-authored-by: Anton Pirker <[email protected]>
1 parent 1144c95 commit 049b5e8

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

docs/platforms/python/feature-flags/index.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Evaluation tracking typically requires enabling an SDK integration. Integrations
1717
- [Generic (API)](/platforms/python/feature-flags/#generic-api)
1818
- [LaunchDarkly](/platforms/python/integrations/launchdarkly/)
1919
- [OpenFeature](/platforms/python/integrations/openfeature/)
20+
- [Statsig](/platforms/python/integrations/statsig/)
2021
- [Unleash](/platforms/python/integrations/unleash/)
2122

2223
### Generic API

docs/platforms/python/integrations/index.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra
6161

6262
### Feature Flags
6363

64-
| | **Auto-enabled** |
65-
| ----------------------------------------------------------------------------------------------------------------------- | :--------------: |
66-
| <LinkWithPlatformIcon platform="python" label="LaunchDarkly" url="/platforms/python/integrations/feature-flags/launchdarkly" /> | |
67-
| <LinkWithPlatformIcon platform="python" label="OpenFeature" url="/platforms/python/integrations/feature-flags/openfeature" /> | |
68-
| <LinkWithPlatformIcon platform="python" label="Unleash" url="/platforms/python/integrations/feature-flags/unleash" /> | |
64+
| | **Auto-enabled** |
65+
| ------------------------------------------------------------------------------------------------------------------ | :--------------: |
66+
| <LinkWithPlatformIcon platform="python" label="LaunchDarkly" url="/platforms/python/integrations/launchdarkly" /> | |
67+
| <LinkWithPlatformIcon platform="python" label="OpenFeature" url="/platforms/python/integrations/openfeature" /> | |
68+
| <LinkWithPlatformIcon platform="python" label="Statsig" url="/platforms/python/integrations/statsig" /> | |
69+
| <LinkWithPlatformIcon platform="python" label="Unleash" url="/platforms/python/integrations/unleash" /> | |
6970

7071
### Cloud Computing
7172

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Statsig
3+
description: "Learn how to use Sentry with Statsig."
4+
---
5+
6+
<PlatformContent includePath="feature-flags/prerelease-alert" />
7+
8+
The [Statsig](https://www.statsig.com/) integration tracks feature flag evaluations produced by the Statsig Python Server 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 from Statsig's `check_gate` function.** Learn more about [Statsig feature gates](https://docs.statsig.com/feature-flags/working-with/).
9+
10+
## Install
11+
12+
Install `sentry-sdk` from PyPI with the `statsig` extra.
13+
14+
```bash
15+
pip install --upgrade 'sentry-sdk[statsig]'
16+
```
17+
18+
## Configure
19+
20+
Add `StatsigIntegration` to your `integrations` list:
21+
22+
```python
23+
import sentry_sdk
24+
from sentry_sdk.integrations.statsig import StatsigIntegration
25+
26+
sentry_sdk.init(
27+
dsn="___PUBLIC_DSN___",
28+
# Add data like request headers and IP for users, if applicable;
29+
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
30+
send_default_pii=True,
31+
integrations=[StatsigIntegration()],
32+
)
33+
```
34+
35+
For more information on how to use Statsig, read Statsig's [Python reference](https://docs.statsig.com/server/pythonSDK) and [quickstart guide](https://docs.statsig.com/guides/first-feature).
36+
37+
## Verify
38+
39+
Test the integration by evaluating a feature flag using your Statsig SDK before capturing an exception.
40+
41+
```python {tabTitle: Python, using is_enabled}
42+
import sentry_sdk
43+
from statsig.statsig_user import StatsigUser
44+
from statsig import statsig
45+
46+
import time
47+
48+
statsig.initialize("server-secret-key")
49+
while not statsig.is_initialized():
50+
time.sleep(0.2)
51+
52+
result = statsig.check_gate(StatsigUser("my-user-id"), "my-feature-gate")
53+
sentry_sdk.capture_exception(Exception("Something went wrong!"))
54+
```
55+
56+
Visit the [Sentry website](https://sentry.io/issues/) and confirm that your error
57+
event has recorded the feature flag "my-feature-gate", and its value is equal to `result`.
58+
59+
## Supported Versions
60+
61+
- statsig >= 0.55.3
62+
- sentry-sdk >= 2.22.0
63+
- python >= 3.7
64+
65+
<PlatformContent includePath="feature-flags/next-steps" />

0 commit comments

Comments
 (0)