From fe943f638949702d95c892524e211357312bbdef Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:29:04 -0800 Subject: [PATCH 01/13] feat(flags): document python UnleashIntegration --- docs/platforms/python/unleash/index.mdx | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 docs/platforms/python/unleash/index.mdx diff --git a/docs/platforms/python/unleash/index.mdx b/docs/platforms/python/unleash/index.mdx new file mode 100644 index 0000000000000..554f278b4c57b --- /dev/null +++ b/docs/platforms/python/unleash/index.mdx @@ -0,0 +1,61 @@ +--- +title: Unleash +description: "Learn how to use Sentry with Unleash." +--- + + + +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` and `UnleashClient` from PyPI. The minimum versions to use this integration are TODO: and 6.0.1, respectively. + +```bash +pip install --upgrade sentry-sdk UnleashClient +``` + +## Configure + +Add a `UnleashIntegration` to your `integrations` list: + +```python +import sentry_sdk +from sentry_sdk.integrations.unleash import UnleashIntegration +from UnleashClient import UnleashClient + +unleash_client = UnleashClient( + url="/api/", # "http://localhost:4242/api/" if you are self-hosting Unleash. + app_name="my-app", # Identifies your app in the Unleash UI. + custom_headers={"Authorization": os.environ["UNLEASH_CLIENT_API_TOKEN"]} +) + +unleash_integration = UnleashIntegration(unleash_client) + +sentry_sdk.init( + dsn="___PUBLIC_DSN___", + integrations=[ + unleash_integration, + ], +) +``` + +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 + +The integration is tested by evaluating a feature flag using your Unleash SDK before capturing an exception. + +```python +import sentry_sdk + +# Re-use `unleash_client` from the previous step. +test_flag_enabled = unleash_client.is_enabled("test-flag") + +sentry_sdk.capture_exception(Exception("Something went wrong!")) +``` + +Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag" and its value +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). + + From f5ecd05b142a5de0f428588f92cef433217b8f1b Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:30:21 -0800 Subject: [PATCH 02/13] ref versioning note --- docs/platforms/python/unleash/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/unleash/index.mdx b/docs/platforms/python/unleash/index.mdx index 554f278b4c57b..1d5fb2cefe851 100644 --- a/docs/platforms/python/unleash/index.mdx +++ b/docs/platforms/python/unleash/index.mdx @@ -9,7 +9,7 @@ The [Unleash](https://www.getunleash.io/) integration tracks feature flag evalua ## Install -Install `sentry-sdk` and `UnleashClient` from PyPI. The minimum versions to use this integration are TODO: and 6.0.1, respectively. +Install `sentry-sdk` (>=TODO:) and `UnleashClient` (>=6.0.1) from PyPI. ```bash pip install --upgrade sentry-sdk UnleashClient From f91ef931601dd36c273bcb99f304fd9e85dc2018 Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:33:49 -0800 Subject: [PATCH 03/13] Reword note on get_variant --- docs/platforms/python/unleash/index.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/platforms/python/unleash/index.mdx b/docs/platforms/python/unleash/index.mdx index 1d5fb2cefe851..8c1c64fbdbdeb 100644 --- a/docs/platforms/python/unleash/index.mdx +++ b/docs/platforms/python/unleash/index.mdx @@ -56,6 +56,8 @@ sentry_sdk.capture_exception(Exception("Something went wrong!")) ``` Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag" and its value -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). +is equal to `test_flag_enabled`. + +Note that we also track the `"enabled"` field in the results of [`get_variant()`](https://docs.getunleash.io/reference/sdks/python#getting-a-variant) calls. From 92ed334b4e4ab28c0c78514f80c27730f72f7bde Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:38:07 -0800 Subject: [PATCH 04/13] get_variant example --- docs/platforms/python/unleash/index.mdx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/platforms/python/unleash/index.mdx b/docs/platforms/python/unleash/index.mdx index 8c1c64fbdbdeb..fbb5a68b45dbc 100644 --- a/docs/platforms/python/unleash/index.mdx +++ b/docs/platforms/python/unleash/index.mdx @@ -46,7 +46,7 @@ For more information on how to use Unleash, read Unleash's [Python reference](ht The integration is tested by evaluating a feature flag using your Unleash SDK before capturing an exception. -```python +```python {tabTitle: Python, using is_enabled} import sentry_sdk # Re-use `unleash_client` from the previous step. @@ -55,9 +55,17 @@ test_flag_enabled = unleash_client.is_enabled("test-flag") sentry_sdk.capture_exception(Exception("Something went wrong!")) ``` -Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag" and its value -is equal to `test_flag_enabled`. +```python {tabTitle: Python, using get_variant} +import sentry_sdk + +# Re-use `unleash_client` from the previous step. +test_flag_variant = unleash_client.get_variant("test-flag") +test_flag_enabled = test_flag_variant["enabled"] -Note that we also track the `"enabled"` field in the results of [`get_variant()`](https://docs.getunleash.io/reference/sdks/python#getting-a-variant) calls. +sentry_sdk.capture_exception(Exception("Something went wrong!")) +``` + +Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag", and its value +is equal to `test_flag_enabled`. From 09b3ff6a3a25b721ef1aee198bf80060771294a7 Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Thu, 26 Dec 2024 16:39:10 -0800 Subject: [PATCH 05/13] import os --- docs/platforms/python/unleash/index.mdx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/platforms/python/unleash/index.mdx b/docs/platforms/python/unleash/index.mdx index fbb5a68b45dbc..bcb15006fa42f 100644 --- a/docs/platforms/python/unleash/index.mdx +++ b/docs/platforms/python/unleash/index.mdx @@ -21,6 +21,8 @@ Add a `UnleashIntegration` to your `integrations` list: ```python import sentry_sdk +import os + from sentry_sdk.integrations.unleash import UnleashIntegration from UnleashClient import UnleashClient From 2c5e06cf3ee980ee7aac7650107089eb068a9523 Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:51:54 -0800 Subject: [PATCH 06/13] Move to integrations folder --- .../python/{ => integrations}/unleash/index.mdx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) rename docs/platforms/python/{ => integrations}/unleash/index.mdx (88%) diff --git a/docs/platforms/python/unleash/index.mdx b/docs/platforms/python/integrations/unleash/index.mdx similarity index 88% rename from docs/platforms/python/unleash/index.mdx rename to docs/platforms/python/integrations/unleash/index.mdx index bcb15006fa42f..822d52daed572 100644 --- a/docs/platforms/python/unleash/index.mdx +++ b/docs/platforms/python/integrations/unleash/index.mdx @@ -17,7 +17,7 @@ pip install --upgrade sentry-sdk UnleashClient ## Configure -Add a `UnleashIntegration` to your `integrations` list: +Add `UnleashIntegration` to your `integrations` list: ```python import sentry_sdk @@ -27,18 +27,18 @@ from sentry_sdk.integrations.unleash import UnleashIntegration from UnleashClient import UnleashClient unleash_client = UnleashClient( - url="/api/", # "http://localhost:4242/api/" if you are self-hosting Unleash. - app_name="my-app", # Identifies your app in the Unleash UI. - custom_headers={"Authorization": os.environ["UNLEASH_CLIENT_API_TOKEN"]} + url="/api/", # "http://localhost:4242/api/" if you are self-hosting Unleash + app_name="my-app", # Identifies your app in the Unleash UI + custom_headers={ + "Authorization": os.environ["UNLEASH_CLIENT_API_TOKEN"] # See 'client token' docs + } ) unleash_integration = UnleashIntegration(unleash_client) sentry_sdk.init( dsn="___PUBLIC_DSN___", - integrations=[ - unleash_integration, - ], + integrations=[unleash_integration], ) ``` From 4c72a149efe1aac4fe8246c97b8f002b11a19b27 Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:58:34 -0800 Subject: [PATCH 07/13] Add to integrations index --- docs/platforms/python/integrations/index.mdx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/platforms/python/integrations/index.mdx b/docs/platforms/python/integrations/index.mdx index b306e5dcc0164..6c26186eba1e0 100644 --- a/docs/platforms/python/integrations/index.mdx +++ b/docs/platforms/python/integrations/index.mdx @@ -59,12 +59,13 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra | | ✓ | | | | -## Feature Flags +### Feature Flags | | **Auto-enabled** | | ----------------------------------------------------------------------------------------------------------------------- | :--------------: | -| | | -| | | +| | | +| | | +| | | ### Cloud Computing From 64ccd98d22d429fd2e5330d249e3dc4fef5f1345 Mon Sep 17 00:00:00 2001 From: Andrew Liu <159852527+aliu39@users.noreply.github.com> Date: Fri, 27 Dec 2024 13:44:31 -0800 Subject: [PATCH 08/13] Review comments --- .../platforms/python/integrations/unleash/index.mdx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/platforms/python/integrations/unleash/index.mdx b/docs/platforms/python/integrations/unleash/index.mdx index 822d52daed572..4ca01792264dc 100644 --- a/docs/platforms/python/integrations/unleash/index.mdx +++ b/docs/platforms/python/integrations/unleash/index.mdx @@ -27,10 +27,11 @@ from sentry_sdk.integrations.unleash import UnleashIntegration from UnleashClient import UnleashClient unleash_client = UnleashClient( - url="/api/", # "http://localhost:4242/api/" if you are self-hosting Unleash - app_name="my-app", # Identifies your app in the Unleash UI + url="/api/", # "http://localhost:4242/api/" if you are self-hosting Unleash. + app_name="my-app", # Identifies your app in the Unleash UI. custom_headers={ - "Authorization": os.environ["UNLEASH_CLIENT_API_TOKEN"] # See 'client token' docs + # See https://docs.getunleash.io/how-to/how-to-create-api-tokens + "Authorization": os.environ["UNLEASH_CLIENT_API_TOKEN"] } ) @@ -46,7 +47,7 @@ For more information on how to use Unleash, read Unleash's [Python reference](ht ## Verify -The integration is tested by evaluating a feature flag using your Unleash SDK before capturing an exception. +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 @@ -67,7 +68,7 @@ test_flag_enabled = test_flag_variant["enabled"] sentry_sdk.capture_exception(Exception("Something went wrong!")) ``` -Visit the Sentry website and confirm that your error event has recorded the feature flag "test-flag", and its value -is equal to `test_flag_enabled`. +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`. From 61ec0758d43b0673a0af014bab4b4b69ec050ac7 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Tue, 7 Jan 2025 15:14:37 +0100 Subject: [PATCH 09/13] Update docs/platforms/python/integrations/unleash/index.mdx Co-authored-by: Colton Allen --- docs/platforms/python/integrations/unleash/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/platforms/python/integrations/unleash/index.mdx b/docs/platforms/python/integrations/unleash/index.mdx index 4ca01792264dc..237fd32238be2 100644 --- a/docs/platforms/python/integrations/unleash/index.mdx +++ b/docs/platforms/python/integrations/unleash/index.mdx @@ -39,7 +39,7 @@ unleash_integration = UnleashIntegration(unleash_client) sentry_sdk.init( dsn="___PUBLIC_DSN___", - integrations=[unleash_integration], + integrations=[UnleashIntegration()], ) ``` From 8550c48ecf6fee703e2cde87926a963afd4a0801 Mon Sep 17 00:00:00 2001 From: Colton Allen Date: Tue, 7 Jan 2025 11:10:31 -0600 Subject: [PATCH 10/13] Fix merge conflict --- docs/platforms/python/integrations/index.mdx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/docs/platforms/python/integrations/index.mdx b/docs/platforms/python/integrations/index.mdx index 5a4f62be0f97e..ec53c3df76812 100644 --- a/docs/platforms/python/integrations/index.mdx +++ b/docs/platforms/python/integrations/index.mdx @@ -63,14 +63,9 @@ The Sentry SDK uses integrations to hook into the functionality of popular libra | | **Auto-enabled** | | ----------------------------------------------------------------------------------------------------------------------- | :--------------: | -<<<<<<< HEAD -| | | -| | | -| | | -======= | | | | | | ->>>>>>> master +| | | ### Cloud Computing From 0c32482905a0e7b7b75a9b1e4883ba76d55dc037 Mon Sep 17 00:00:00 2001 From: Colton Allen Date: Tue, 7 Jan 2025 11:13:19 -0600 Subject: [PATCH 11/13] Remove unnecessary documentation of unleash client initialization --- .../integrations/feature-flags/unleash.mdx | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/docs/platforms/python/integrations/feature-flags/unleash.mdx b/docs/platforms/python/integrations/feature-flags/unleash.mdx index 237fd32238be2..a9f38d939206d 100644 --- a/docs/platforms/python/integrations/feature-flags/unleash.mdx +++ b/docs/platforms/python/integrations/feature-flags/unleash.mdx @@ -9,7 +9,7 @@ The [Unleash](https://www.getunleash.io/) integration tracks feature flag evalua ## Install -Install `sentry-sdk` (>=TODO:) and `UnleashClient` (>=6.0.1) from PyPI. +Install `sentry-sdk` (>=2.19.3) and `UnleashClient` (>=6.0.1) from PyPI. ```bash pip install --upgrade sentry-sdk UnleashClient @@ -24,18 +24,6 @@ import sentry_sdk import os from sentry_sdk.integrations.unleash import UnleashIntegration -from UnleashClient import UnleashClient - -unleash_client = UnleashClient( - url="/api/", # "http://localhost:4242/api/" if you are self-hosting Unleash. - app_name="my-app", # Identifies your app in the Unleash UI. - custom_headers={ - # See https://docs.getunleash.io/how-to/how-to-create-api-tokens - "Authorization": os.environ["UNLEASH_CLIENT_API_TOKEN"] - } -) - -unleash_integration = UnleashIntegration(unleash_client) sentry_sdk.init( dsn="___PUBLIC_DSN___", @@ -52,7 +40,6 @@ Test the integration by evaluating a feature flag using your Unleash SDK before ```python {tabTitle: Python, using is_enabled} import sentry_sdk -# Re-use `unleash_client` from the previous step. test_flag_enabled = unleash_client.is_enabled("test-flag") sentry_sdk.capture_exception(Exception("Something went wrong!")) @@ -61,7 +48,6 @@ sentry_sdk.capture_exception(Exception("Something went wrong!")) ```python {tabTitle: Python, using get_variant} import sentry_sdk -# Re-use `unleash_client` from the previous step. test_flag_variant = unleash_client.get_variant("test-flag") test_flag_enabled = test_flag_variant["enabled"] From a0d849bf5a067968e4b8691df31a401c706478b9 Mon Sep 17 00:00:00 2001 From: Colton Allen Date: Tue, 7 Jan 2025 12:51:09 -0600 Subject: [PATCH 12/13] Remove os import --- docs/platforms/python/integrations/feature-flags/unleash.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/platforms/python/integrations/feature-flags/unleash.mdx b/docs/platforms/python/integrations/feature-flags/unleash.mdx index a9f38d939206d..bb8e867df3fbe 100644 --- a/docs/platforms/python/integrations/feature-flags/unleash.mdx +++ b/docs/platforms/python/integrations/feature-flags/unleash.mdx @@ -21,8 +21,6 @@ Add `UnleashIntegration` to your `integrations` list: ```python import sentry_sdk -import os - from sentry_sdk.integrations.unleash import UnleashIntegration sentry_sdk.init( From d4058163914b7d545e61367639772f4f59dfcbec Mon Sep 17 00:00:00 2001 From: Colton Allen Date: Tue, 7 Jan 2025 12:56:44 -0600 Subject: [PATCH 13/13] Add unleash imports --- docs/platforms/python/integrations/feature-flags/unleash.mdx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/platforms/python/integrations/feature-flags/unleash.mdx b/docs/platforms/python/integrations/feature-flags/unleash.mdx index bb8e867df3fbe..04c4d25d11f11 100644 --- a/docs/platforms/python/integrations/feature-flags/unleash.mdx +++ b/docs/platforms/python/integrations/feature-flags/unleash.mdx @@ -37,7 +37,9 @@ Test the integration by evaluating a feature flag using your Unleash SDK before ```python {tabTitle: Python, using is_enabled} import sentry_sdk +from UnleashClient import UnleashClient +unleash_client = UnleashClient(...) # See Unleash quickstart. test_flag_enabled = unleash_client.is_enabled("test-flag") sentry_sdk.capture_exception(Exception("Something went wrong!")) @@ -45,7 +47,9 @@ sentry_sdk.capture_exception(Exception("Something went wrong!")) ```python {tabTitle: Python, using get_variant} import sentry_sdk +from UnleashClient import UnleashClient +unleash_client = UnleashClient(...) # See Unleash quickstart. test_flag_variant = unleash_client.get_variant("test-flag") test_flag_enabled = test_flag_variant["enabled"]