| title | Flagsmith |
|---|---|
| description | Learn how to use Sentry with Flagsmith. |
Flagsmith relies on the OpenFeature integration to track feature flag evaluations produced by the OpenFeature 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 sentry-sdk from PyPI with the openfeature extra.
pip install "sentry-sdk[openfeature]" openfeature-provider-flagsmithuv add "sentry-sdk[openfeature]" openfeature-provider-flagsmithSet FlagsmithProvider() as the provider for the OpenFeature client, then add OpenFeatureIntegration() to your integrations list:
import flagsmith
import sentry_sdk
from openfeature import api
from openfeature_flagsmith.provider import FlagsmithProvider
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
flagsmith_client = flagsmith.Flagsmith(
environment_key='<Flagsmith public environment key>',
)
flagsmith_provider = FlagsmithProvider(
client=flagsmith_client,
)
api.set_provider(flagsmith_provider)
sentry_sdk.init(
dsn="___PUBLIC_DSN___",
# Add data like request headers and IP for users, if applicable;
# see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
send_default_pii=True,
integrations=[
OpenFeatureIntegration(),
],
)The integration is tested by evaluating a feature flag using your OpenFeature SDK before capturing an exception.
from openfeature import api
import sentry_sdk
client = api.get_client()
client.get_boolean_value("hello", default_value=False)
sentry_sdk.capture_exception(Exception("Something went wrong!"))Visit the Sentry website and confirm that your error event has recorded the feature flag "hello" and its value "false".
- openfeature-sdk >= 0.7.1
- sentry-sdk >= 2.19.2
- python >= 3.9