The function Flag is declared in the Sentry code base. For self-hosted users, these flags are then configured via sentry.conf.py. For Sentry’s SaaS deployment, Flagr is used to configure flags in production.

You can find a list of available features by looking at sentry/features/__init__.py. They are stated on FeatureManager as follows:

# Don't set entity_feature, or set it to False if you don't plan to use Flagr
default_manager.add("organizations:onboarding", OrganizationFeature, entity_feature=True)
Copy the code

This feature can be enabled in your sentry.conf.py using the following, usually located in ~/.sentry/ :

SENTRY_FEATURES["organizations:onboarding"] = True
Copy the code

You can use context Manager to change the state of the feature flag in the test.

  • Develop. Sentry. Dev/testing / # se…

Create a new Feature Flag

Determine the scope that functionality should have

Functions can be scoped by organization and project. If you are not sure whether you need the Project functionality, create an Organization level. In this example, we will build a feature called test-feature scoped at the organization level.

Add your functionality to server.py

Conf /server.py contains many of the default Settings in your application. Here, you will add your functionality and decide what defaults it should keep unless specified by the user.

  • Github.com/getsentry/s…

The SENTRY_FEATURES dictionary contains all the functionality in the application and its corresponding scope. By default, your functionality should be disabled:

SENTRY_FEATURES = {
    'organizations:test-feature': False.'auth:register': True.#...
    'projects:minidump': False,}Copy the code

Add your features to FeatureManager

FeatureManager handles application functionality. We added all the features to FeatureManager, including the types of features we wanted to add to the file/SRC /sentry/features/__init__.py.

If you plan to use Flagr in production, add a third optional Boolean parameter when adding functionality, such as:

  • Develop. Sentry. Dev/feature – the fla…
default_manager.add('organizations:test-feature', OrganizationFeature, True)
Copy the code

If you do not intend to use Flagr, do not pass this third parameter, for example:

default_manager.add('organizations:test-feature', OrganizationFeature)
Copy the code

Add it to Organization Model Serializer

Organization model serializer (SRC/sentry/API/serializers/models/Organization. Py) built a list, called feature_list for front end use. By default, all functionality is checked and existing functionality is added to the list. If your functionality requires additional custom logic, you must update organization Serializer

Using Model Flags (less common)

Sometimes the flag on model is used to indicate feature flag, as shown below. This is not recommended unless there is a specific reason to change the Model. For example, the require_2FA Flag affects the behavior of the back end to enforce two-factor authentication.

feature_list = []

if getattr(obj.flags, 'allow_joinleave'):
    feature_list.append('open-membership')
if not getattr(obj.flags, 'disable_shared_issues'):
    feature_list.append('shared-issues')
if getattr(obj.flags, 'require_2fa'):
    feature_list.append('require-2fa')
Copy the code

Check your functionality

In Python code

The Has method of FeatureManager checks to see if this feature exists. The HAS method receives the name of the feature, which is the object corresponding to the scope of the feature (that is, the organization of the organization-level feature or the project of the project-level feature) and actor (aka User). In our example, this functionality would be added as follows:

if features.has('organizations:test-feature', obj, actor=user):
    feature_list.append('test-feature')
Copy the code

If this is enabled for the organization and a given user type, the feature will only be added to the Feature_list. Note that when we provided the feature to the front end, we removed the scope prefix and our ‘Organizations :test-feature’ became ‘test-feature’.

In JavaScript

There is a difference between using flag in Sentry and GetSentry. At this stage, you are not ready to use your feature flag in GetSentry, but you can use it in Sentry.

Declarative functionality with Feature components

React uses the declarative programming paradigm. Therefore, we have a Utility component that hides components based on the feature flags available to the organization/project

import Feature from 'app/components/acl/feature';

const toRender = (
  <Feature features={['test-feature']} >
    <MyComponentToFlag />
  </Feature>
);
Copy the code

Command function Flag check

There are some exceptions to forcing the React component (such as table headers/columns). In this case, the Organization/Project object has an array of feature flags, which you can use in the following ways:

const {organization} = this.props;

// Method 2
organization.features.includes('test-feature'); // evals to True/False
Copy the code

Enable functionality in development

In Sentry, you can run Sentry DevServer to see your changes in development mode. If you want to see feature flag behind the changes, you will need to open the file on the local computer ~ /. Sentry/sentry. Config. Py. This file contains the local Settings of the Sentry application, which can be viewed and edited. If you want to turn flag on or off, add it to your profile:

SENTRY_FEATURES['organizations:test-feature'] = True
Copy the code

Where, SENTRY_FEATURES will correspond to SENTRY_FEATURES in Step 2. Set it to True if you want this feature to be available, and False otherwise.

Flagr(Sentry SaaS) in development

Typically, you don’t need to run Flagr in development to test your feature markers. If you do want to run Flagr, you need to run getSentry:

  1. Setting environment variables:export SENTRY_USE_FLAGR=true
  2. Start your devservices

You can find your local flagr instance at localhost:18000

  • Develop. Sentry. Dev/sentry – v – g…
  • Develop. Sentry. Dev/services/DE…

Enable your functionality in production (Sentry SaaS)

The function Flag is declared in the Sentry code base. For self-hosted users, these flags are then configured via sentry.conf.py. For SaaS deployments of Sentry, Flagr is used to configure flags in production.

If you want to enable your functionality for a subset of production users, you need to set your functionality in Flagr. If you didn’t make sure you passed the third option when you added flags to sentry, Flagr will know to check this feature in production.

default_manager.add("organizations:onboarding", OrganizationFeature, True)  # NOQA
Copy the code

More and more

  • Sentry Enterprise level Data security solution – Relay getting started
  • Sentry Enterprise level data security solution – Relay operation mode
  • Sentry Enterprise level data security solution – Relay configuration option
  • Sentry Enterprise level data security solution – Relay monitoring & Metrics Collection
  • Sentry Enterprise level data security solution – Relay project configuration
  • Sentry Developer Contribution Guide – SDK Development (Performance Monitoring: Sentry SDK API Evolution)