Skip to content

Commit 7eaf820

Browse files
committed
add statsig too
2 parents c25c33f + 2b067e9 commit 7eaf820

File tree

19 files changed

+598
-50
lines changed

19 files changed

+598
-50
lines changed

.github/workflows/test-integrations-flags.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
strategy:
3030
fail-fast: false
3131
matrix:
32-
python-version: ["3.8","3.9","3.12","3.13"]
32+
python-version: ["3.7","3.8","3.9","3.12","3.13"]
3333
# python3.6 reached EOL and is no longer being supported on
3434
# new versions of hosted runners on Github Actions
3535
# ubuntu-20.04 is the last version that supported python3.6
@@ -55,6 +55,10 @@ jobs:
5555
run: |
5656
set -x # print commands that are executed
5757
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-openfeature"
58+
- name: Test statsig pinned
59+
run: |
60+
set -x # print commands that are executed
61+
./scripts/runtox.sh --exclude-latest "py${{ matrix.python-version }}-statsig"
5862
- name: Test unleash pinned
5963
run: |
6064
set -x # print commands that are executed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- Set level based on status code for HTTP client breadcrumbs (#4004) by @sentrivana
1818
- Don't set transaction status to error on `sys.exit(0)` (#4025) by @sentrivana
1919
- Continuous profiling sample rate (#4002) by @Zylphrex
20+
21+
Set `profile_session_sample_rate=1.0` in your `init()` to collect continuous profiles for 100% of profile sessions. See https://docs.sentry.io/platforms/python/profiling/#enable-continuous-profiling for more information.
2022
- Track and report spans that were dropped (#4005) by @constantinius
2123
- Change continuous profile buffer size (#3987) by @Zylphrex
2224
- Handle `MultiPartParserError` to avoid internal sentry crash (#4001) by @orhanhenrik
@@ -40,7 +42,7 @@
4042
## 2.20.0
4143

4244
- **New integration:** Add [Typer](https://typer.tiangolo.com/) integration (#3869) by @patrick91
43-
45+
4446
For more information, see the documentation for the [TyperIntegration](https://docs.sentry.io/platforms/python/integrations/typer/).
4547

4648
- **New integration:** Add [Unleash](https://www.getunleash.io/) feature flagging integration (#3888) by @aliu39
@@ -122,7 +124,7 @@
122124
### Various fixes & improvements
123125

124126
- **New integration:** Add [LaunchDarkly](https://launchdarkly.com/) integration (#3648) by @cmanallen
125-
127+
126128
For more information, see the documentation for the [LaunchDarklyIntegration](https://docs.sentry.io/platforms/python/integrations/launchdarkly/).
127129

128130
- **New integration:** Add [OpenFeature](https://openfeature.dev/) feature flagging integration (#3648) by @cmanallen

requirements-linting.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ flake8-bugbear
1515
pep8-naming
1616
pre-commit # local linting
1717
httpcore
18-
openfeature-sdk
1918
launchdarkly-server-sdk
19+
openfeature-sdk
20+
statsig
2021
UnleashClient
2122
typer
2223
strawberry-graphql

scripts/populate_tox/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"openfeature": {
3030
"package": "openfeature-sdk",
3131
},
32+
"statsig": {
33+
"package": "statsig",
34+
},
3235
"strawberry": {
3336
"package": "strawberry-graphql[fastapi,flask]",
3437
"deps": {

scripts/populate_tox/tox.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ setenv =
772772
spark: TESTPATH=tests/integrations/spark
773773
starlette: TESTPATH=tests/integrations/starlette
774774
starlite: TESTPATH=tests/integrations/starlite
775+
statsig: TESTPATH=tests/integrations/statsig
775776
sqlalchemy: TESTPATH=tests/integrations/sqlalchemy
776777
strawberry: TESTPATH=tests/integrations/strawberry
777778
tornado: TESTPATH=tests/integrations/tornado

scripts/split_tox_gh_actions/split_tox_gh_actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"Flags": [
8888
"launchdarkly",
8989
"openfeature",
90+
"statsig",
9091
"unleash",
9192
],
9293
"Gevent": [

sentry_sdk/consts.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CompressionAlgo(Enum):
3838
from typing import Any
3939
from typing import Sequence
4040
from typing import Tuple
41+
from typing_extensions import Literal
4142
from typing_extensions import TypedDict
4243

4344
from sentry_sdk._types import (
@@ -528,6 +529,7 @@ def __init__(
528529
profiles_sample_rate=None, # type: Optional[float]
529530
profiles_sampler=None, # type: Optional[TracesSampler]
530531
profiler_mode=None, # type: Optional[ProfilerMode]
532+
profile_lifecycle="manual", # type: Literal["manual", "trace"]
531533
profile_session_sample_rate=None, # type: Optional[float]
532534
auto_enabling_integrations=True, # type: bool
533535
disabled_integrations=None, # type: Optional[Sequence[sentry_sdk.integrations.Integration]]

sentry_sdk/integrations/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def iter_default_integrations(with_auto_enabling_integrations):
151151
"sanic": (0, 8),
152152
"sqlalchemy": (1, 2),
153153
"starlite": (1, 48),
154+
"statsig": (0, 55, 3),
154155
"strawberry": (0, 209, 5),
155156
"tornado": (6, 0),
156157
"typer": (0, 15),

sentry_sdk/integrations/statsig.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from functools import wraps
2+
from typing import Any, TYPE_CHECKING
3+
4+
from sentry_sdk.feature_flags import add_feature_flag
5+
from sentry_sdk.integrations import Integration, DidNotEnable, _check_minimum_version
6+
from sentry_sdk.utils import parse_version
7+
8+
try:
9+
from statsig import statsig as statsig_module
10+
from statsig.version import __version__ as STATSIG_VERSION
11+
except ImportError:
12+
raise DidNotEnable("statsig is not installed")
13+
14+
if TYPE_CHECKING:
15+
from statsig.statsig_user import StatsigUser
16+
17+
18+
class StatsigIntegration(Integration):
19+
identifier = "statsig"
20+
21+
@staticmethod
22+
def setup_once():
23+
# type: () -> None
24+
version = parse_version(STATSIG_VERSION)
25+
_check_minimum_version(StatsigIntegration, version, "statsig")
26+
27+
# Wrap and patch evaluation method(s) in the statsig module
28+
old_check_gate = statsig_module.check_gate
29+
30+
@wraps(old_check_gate)
31+
def sentry_check_gate(user, gate, *args, **kwargs):
32+
# type: (StatsigUser, str, *Any, **Any) -> Any
33+
enabled = old_check_gate(user, gate, *args, **kwargs)
34+
add_feature_flag(gate, enabled)
35+
return enabled
36+
37+
statsig_module.check_gate = sentry_check_gate

sentry_sdk/integrations/unleash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class UnleashIntegration(Integration):
1616
@staticmethod
1717
def setup_once():
1818
# type: () -> None
19-
# Wrap and patch evaluation methods (instance methods)
19+
# Wrap and patch evaluation methods (class methods)
2020
old_is_enabled = UnleashClient.is_enabled
2121

2222
@wraps(old_is_enabled)

0 commit comments

Comments
 (0)