Integrate Flagsmith with Sentry to enable feature flag Change Tracking.
Along with Change Tracking, Sentry also offers Evaluation Tracking. Integrating with Evaluation Tracking is currently only possible via our OpenFeature provider.
Change Tracking Setup
- In Sentry
- Visit the feature flags settings page in a new tab.
- Click the "Add New Provider" button.
- Select "Generic" in the dropdown that says "Select a provider".
- Copy the provided Sentry webhook URL — we'll use that soon.
- Do not close this page! We're not done yet.
- In Flagsmith
- Go to Integrations > Sentry > Add Integration.
- Choose the Environment from which Sentry will receive feature flag change events.
- Paste the URL copied above into "Sentry webhook URL".
- Insert a secret (10-60 characters) and copy it.
- Click "Save". ✅
- Back to Sentry
- Paste the secret copied above.
- Click "Add Provider". ✅
Flag change events will now be sent to Sentry, and should be displayed in issue details. For more information, visit Sentry's Issue Details page documentation.
Evaluation Tracking example
In order to add evaluated feature flags to a Sentry issue when it occurs, events must be sent via Sentry SDK, i.e. the same SDK used to send application errors to Sentry.
Flagsmith relies on the OpenFeature SDK and its integration with Sentry.
Python
Sentry offers good documentation on how to integrate the Sentry SDK with the OpenFeature SDK. We'll extend it a bit adding an example of using it with Flagsmith.
You'll need to install the following libraries:
pip install "sentry-sdk[openfeature]"
pip install openfeature-provider-flagsmith
The following snippet is a micro-application that reports feature flags to Sentry when an exception is raised.
import flagsmith
import sentry_sdk
from openfeature import api as of_api
from openfeature_flagsmith.provider import FlagsmithProvider
from sentry_sdk.integrations.openfeature import OpenFeatureIntegration
app = flask.Flask(__name__)
flagsmith_client = flagsmith.Flagsmith(
environment_key='<public environment key>',
)
feature_flag_provider = FlagsmithProvider(
client=flagsmith_client,
)
of_api.set_provider(feature_flag_provider)
sentry_sdk.init(
dsn="<Sentry DSN>",
send_default_pii=True,
integrations=[
OpenFeatureIntegration(),
]
)
def apply_discount(price):
of_client = of_api.get_client()
is_discount_enabled = of_client.get_boolean_value('discount_enabled', False)
if is_discount_enabled:
discount = price / 0 # ZeroDivisionError
else:
discount = None
return price * discount # TypeError
You can learn more about feature flags and Sentry issues in their Issue Details documentation.
JavaScript
You'll need to manually call Sentry.FeatureFlagsIntegration.addFeatureFlag
when evaluating a feature flag. Learn more
in the Sentry documentation.