|
| 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