Feature flags & experiments

Monitor errors as you roll out features or run experiments and A/B tests by declaring your feature flag and experiment usage in the BugSnag client. You can use the Features dashboard to identify whether these features have introduced errors into your app.

Declaring active feature flags and experiments

You should declare feature flag and experiment usage to BugSnag at the time a feature or experiment is activated in your app. This ensures that subsequent errors will be associated with the feature flag or experiment usage accurately.

Feature flags are scoped to the context of the current request using a ContextVar.

You can either declare the usage using the following methods on the BugSnag module or in a callback on the Event object:

add_feature_flag

Declare a single feature flag or experiment with variant as an optional second parameter.

bugsnag.add_feature_flag("Checkout button color", "Blue")
bugsnag.add_feature_flag("New checkout flow")

add_feature_flags

Declare multiple feature flags or experiments.

bugsnag.add_feature_flags(
  [
    bugsnag.FeatureFlag("Checkout button color", "Blue"),
    bugsnag.FeatureFlag("New checkout flow")
  ]
)

If add_feature_flags is called again, the new data will be merged with any existing feature flags with the newer variant values taking precedence.

clear_feature_flag

Remove a single feature flag or experiment.

bugsnag.clear_feature_flag("Checkout button color")

clear_feature_flags

Remove all feature flags and experiments.

bugsnag.clear_feature_flags()

Feature and experiment management tools

LaunchDarkly

To use BugSnag with LaunchDarkly, you need to declare the flag to BugSnag whenever you read it from LaunchDarkly:

launch_darkly_client = # get LaunchDarkly client
launch_darkly_context = # get LaunchDarkly context

# Boolean flag
feature_enabled = launch_darkly_client.variation("bool-flag-key", launch_darkly_context, False)

if feature_enabled:
    bugsnag.add_feature_flag("bool-flag-key")
else:
    bugsnag.clear_feature_flag("bool-flag-key")

# String flag
string_flag = launch_darkly_client.variation("string-flag-key", launch_darkly_context, None)

if string_flag:
    bugsnag.add_feature_flag("string-flag-key", string_flag)
else:
    bugsnag.clear_feature_flag("string-flag-key")

For more information, please see the LaunchDarkly Python SDK documentation.

Split

To use BugSnag with Split, you need to declare the flag to BugSnag whenever you read it from Split:

split_client = # get Split client

# Boolean flag
treatment = split_client.get_treatment("key", "bool-split-name")

if treatment == "on":
    bugsnag.add_feature_flag("bool-split-name")
else:
    bugsnag.clear_feature_flag("bool-split-name")

# String flag
treatment = split_client.get_treatment("key", "string-split-name")

if treatment:
    bugsnag.add_feature_flag("string-split-name", treatment)
else:
    bugsnag.clear_feature_flag("string-split-name")

For more information, please see the Split Python SDK documentation.