Skip to content

Commit c6aff34

Browse files
committed
feat(flags): add Unleash feature flagging integration
1 parent f6281f5 commit c6aff34

File tree

5 files changed

+57
-4
lines changed

5 files changed

+57
-4
lines changed

requirements-linting.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ pre-commit # local linting
1717
httpcore
1818
openfeature-sdk
1919
launchdarkly-server-sdk
20+
UnleashClient
2021
typer

requirements-testing.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ socksio
1414
httpcore[http2]
1515
setuptools
1616
Brotli
17+
UnleashClient

sentry_sdk/integrations/unleash.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from functools import wraps
2+
3+
import sentry_sdk
4+
from sentry_sdk.integrations import Integration
5+
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from typing import Optional
10+
from UnleashClient import UnleashClient
11+
12+
13+
class UnleashIntegration(Integration):
14+
identifier = "unleash"
15+
16+
def __init__(self, unleash_client):
17+
# type: (Optional[UnleashClient]) -> None
18+
self.unleash_client = unleash_client
19+
20+
@staticmethod
21+
def setup_once():
22+
# type: () -> None
23+
integration = sentry_sdk.get_client().get_integration(UnleashIntegration)
24+
if integration is None:
25+
return
26+
27+
unleash_client = integration.unleash_client
28+
old_is_enabled = unleash_client.is_enabled
29+
30+
@wraps(old_is_enabled)
31+
def sentry_is_enabled(self, *a, **kw):
32+
# TODO: # type:
33+
key, value = a[0], a[1] # TODO: this is a placeholder
34+
if isinstance(value, bool):
35+
flags = sentry_sdk.get_current_scope().flags
36+
flags.set(key, value)
37+
return old_is_enabled(self, *a, **kw)
38+
39+
unleash_client.is_enabled = sentry_is_enabled # type: ignore
40+
41+
# TODO: get_variant

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def get_file_text(file_name):
8080
"starlette": ["starlette>=0.19.1"],
8181
"starlite": ["starlite>=1.48"],
8282
"tornado": ["tornado>=6"],
83+
"unleash": ["UnleashClient>=6.0.1"],
8384
},
8485
entry_points={
8586
"opentelemetry_propagator": [

tox.ini

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ envlist =
168168
{py3.9,py3.11,py3.12}-langchain-latest
169169
{py3.9,py3.11,py3.12}-langchain-notiktoken
170170

171+
# LaunchDarkly
172+
{py3.8,py3.12,py3.13}-launchdarkly-v9.8.0
173+
{py3.8,py3.12,py3.13}-launchdarkly-latest
174+
171175
# Litestar
172176
{py3.8,py3.11}-litestar-v{2.0}
173177
{py3.8,py3.11,py3.12}-litestar-v{2.6}
@@ -189,10 +193,6 @@ envlist =
189193
{py3.8,py3.12,py3.13}-openfeature-v0.7
190194
{py3.8,py3.12,py3.13}-openfeature-latest
191195

192-
# LaunchDarkly
193-
{py3.8,py3.12,py3.13}-launchdarkly-v9.8.0
194-
{py3.8,py3.12,py3.13}-launchdarkly-latest
195-
196196
# OpenTelemetry (OTel)
197197
{py3.7,py3.9,py3.12,py3.13}-opentelemetry
198198

@@ -291,6 +291,10 @@ envlist =
291291
{py3.7,py3.12,py3.13}-typer-v{0.15}
292292
{py3.7,py3.12,py3.13}-typer-latest
293293

294+
# Unleash
295+
{py3.8,py3.12,py3.13}-unleash-v6.0.1
296+
{py3.8,py3.12,py3.13}-unleash-latest
297+
294298
[testenv]
295299
deps =
296300
# if you change requirements-testing.txt and your change is not being reflected
@@ -572,6 +576,10 @@ deps =
572576
launchdarkly-v9.8.0: launchdarkly-server-sdk~=9.8.0
573577
launchdarkly-latest: launchdarkly-server-sdk
574578

579+
# Unleash
580+
unleash-v6.0.1: UnleashClient~=6.0.1
581+
unleash-latest: UnleashClient
582+
575583
# OpenTelemetry (OTel)
576584
opentelemetry: opentelemetry-distro
577585

@@ -795,6 +803,7 @@ setenv =
795803
tornado: TESTPATH=tests/integrations/tornado
796804
trytond: TESTPATH=tests/integrations/trytond
797805
typer: TESTPATH=tests/integrations/typer
806+
unleash: TESTPATH=tests/integrations/unleash
798807
socket: TESTPATH=tests/integrations/socket
799808

800809
passenv =

0 commit comments

Comments
 (0)