Skip to content

Commit

Permalink
feat(flags): re-publish docs on python unleash and generic integratio…
Browse files Browse the repository at this point in the history
…ns (#12300)

This PR re-publishes them and 
- fixes Unleash sample code (need to call `initialize_client()`) and versioning. 
- moves python generic docs, after changing it from an integration to an API: getsentry/sentry-python#3917

---------

Co-authored-by: Anton Pirker <[email protected]>
  • Loading branch information
aliu39 and antonpirker authored Jan 14, 2025
1 parent c81d6f0 commit 4b81e30
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ To set up evaluation tracking, visit the [explore page](/product/explore/feature

To set up generic evaluation tracking, visit one of our supported languages' pages:
* [JavaScript](/platforms/javascript/configuration/integrations/generic/)
* [Python](/platforms/python/feature-flags/#generic-api)

## Change Tracking

Expand Down
9 changes: 7 additions & 2 deletions docs/organization/integrations/feature-flag/unleash/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ description: Learn about Sentry's Unleash integrations.

## Evaluation Tracking

Support for this is coming soon, starting with [Python sentry-sdk](https://pypi.org/project/sentry-sdk/).
Sentry can track flag evaluations as they happen within your application. Flag evaluations will appear in the "Feature Flag" section of the Issue Details page as a table, with "suspect" flag predictions highlighted in yellow. Learn more about how to interact with feature flag insights within the Sentry UI by reading the [Issue Details page documentation](/product/issues/issue-details/#feature-flags).

### Set Up Evaluation Tracking

To set up evaluation tracking, visit one of our supported languages pages:
* [Python](/platforms/python/integrations/feature-flags/unleash/)

## Change Tracking

Expand All @@ -20,7 +25,7 @@ Enabling Change Tracking is a three-step process. To get started visit the [feat
- One webhook secret can be registered per provider type.
- Select Unleash in the dropdown that says "Select a provider".
2. **Register the webhook URL**.
- Go to your Unleash homepage and navigate to the `/integrations/` page, which can be found by clicking Integrations on the left-hand sidebar navigation, under the Configure heading.
- Go to your Unleash homepage and navigate to the `/integrations/` page, which can be found by clicking Integrations on the left-hand sidebar navigation, under the Configure heading.
- Select the Webhook option. You should be on the `/integrations/create/webhook/` page.
- Copy the provided Sentry webhook URL in settings and paste it into Unleash within their webhook integration UI.
- Make sure the integration is toggled to Enabled.
Expand Down
5 changes: 3 additions & 2 deletions docs/platforms/javascript/common/feature-flags/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ description: With Feature Flags, Sentry tracks feature flag evaluations in your
## Enable Evaluation Tracking

Evaluation tracking requires enabling an SDK integration. Integrations are provider specific. Documentation for supported providers is listed below.
- [OpenFeature](/platforms/javascript/configuration/integrations/openfeature/)
- [LaunchDarkly](/platforms/javascript/configuration/integrations/launchdarkly/)

- [Generic](/platforms/javascript/configuration/integrations/generic/)
- [LaunchDarkly](/platforms/javascript/configuration/integrations/launchdarkly/)
- [OpenFeature](/platforms/javascript/configuration/integrations/openfeature/)

<PlatformContent includePath="feature-flags/enable-change-tracking" />
30 changes: 26 additions & 4 deletions docs/platforms/python/feature-flags/index.mdx
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
---
title: Set Up Feature Flags
sidebar_order: 7000
description: With Feature Flags, Sentry tracks feature flag evaluations in your application, keeps an audit log feature flag changes, and reports any suspicious updates that may have caused an error.
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.
---

<PlatformContent includePath="feature-flags/prerelease-alert" />

A feature flagging integration allows you to manually track feature flag evaluations through an API. These evaluations are collected in memory, and in the event an error occurs, sent to Sentry for review and analysis.


## Prerequisites

* You have the <PlatformLink to="/">Python SDK installed</PlatformLink>.

## Enable Evaluation Tracking

Evaluation tracking requires enabling an SDK integration. Integrations are provider specific. Documentation for supported providers is listed below.
Evaluation tracking typically requires enabling an SDK integration. Integrations are provider specific. Documentation for supported providers is listed below.

- [Generic (API)](/platforms/python/feature-flags/#generic-api)
- [LaunchDarkly](/platforms/python/integrations/launchdarkly/)
- [OpenFeature](/platforms/python/integrations/openfeature/)
- [Unleash](/platforms/python/integrations/unleash/)

### Generic API
The generic API allows you to manually track feature flag evaluations. These
evaluations are held in memory, and in the event an error occurs, sent to
Sentry for review and analysis. Specifically, the generic integration enables
users to integrate with proprietary (or otherwise unsupported) feature flagging
solutions. **At the moment, we only support boolean flag evaluations.**

```python
from sentry_sdk.feature_flags import add_feature_flag

add_feature_flag('test-flag', False) # Records an evaluation and its result.

sentry_sdk.capture_exception(Exception("Something went wrong!"))
```

- [OpenFeature](/platforms/python/integrations/feature-flags/openfeature/)
- [LaunchDarkly](/platforms/python/integrations/feature-flags/launchdarkly/)
Go to your Sentry project and confirm that your error event has recorded the feature flag "test-flag" and its value "false".

<PlatformContent includePath="feature-flags/enable-change-tracking" />
8 changes: 0 additions & 8 deletions docs/platforms/python/integrations/feature-flags/index.mdx

This file was deleted.

64 changes: 64 additions & 0 deletions docs/platforms/python/integrations/unleash/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Unleash
description: "Learn how to use Sentry with Unleash."
---

<PlatformContent includePath="feature-flags/prerelease-alert" />

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

## Install

Install `sentry-sdk` (>=2.20.0) and `UnleashClient` (>=6.0.1) from PyPI.

```bash
pip install --upgrade sentry-sdk UnleashClient
```

## Configure

Add `UnleashIntegration` to your `integrations` list:

```python
import sentry_sdk
from sentry_sdk.integrations.unleash import UnleashIntegration

sentry_sdk.init(
dsn="___PUBLIC_DSN___",
integrations=[UnleashIntegration()],
)
```

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

## Verify

Test the integration by evaluating a feature flag using your Unleash SDK before capturing an exception.

```python {tabTitle: Python, using is_enabled}
import sentry_sdk
from UnleashClient import UnleashClient

unleash = UnleashClient(...) # See Unleash quickstart.
unleash.initialize_client()

test_flag_enabled = unleash.is_enabled("test-flag")
sentry_sdk.capture_exception(Exception("Something went wrong!"))
```

```python {tabTitle: Python, using get_variant}
import sentry_sdk
from UnleashClient import UnleashClient

unleash = UnleashClient(...) # See Unleash quickstart.
unleash.initialize_client()

test_flag_variant = unleash.get_variant("test-flag")
test_flag_enabled = test_flag_variant["enabled"]
sentry_sdk.capture_exception(Exception("Something went wrong!"))
```

Visit the [Sentry website](https://sentry.io/issues/) and confirm that your error
event has recorded the feature flag "test-flag", and its value is equal to `test_flag_enabled`.

<PlatformContent includePath="feature-flags/next-steps" />
12 changes: 12 additions & 0 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,18 @@ const USER_DOCS_REDIRECTS: Redirect[] = [
from: '/platforms/python/tryton/',
to: '/platforms/python/integrations/tryton/',
},
{
from: '/platforms/python/integrations/feature-flags/launchdarkly/',
to: '/platforms/python/integrations/launchdarkly/',
},
{
from: '/platforms/python/integrations/feature-flags/openfeature/',
to: '/platforms/python/integrations/openfeature/',
},
{
from: '/platforms/python/integrations/feature-flags/unleash/',
to: '/platforms/python/integrations/unleash/',
},
{
from: '/clients/python/breadcrumbs/',
to: '/platforms/python/legacy-sdk/breadcrumbs/',
Expand Down

0 comments on commit 4b81e30

Please sign in to comment.