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.
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 current thread.
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.new('Checkout button color', 'Blue')
Bugsnag::FeatureFlag.new('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
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_user = { key: 'user@example.com' }
# Boolean flag
feature_enabled = launch_darkly_client.variation('bool-flag-key', launch_darkly_user, false)
if feature_enabled
Bugsnag.add_feature_flag('bool-flag-key')
else
Bugsnag.clear_feature_flag('bool-flag-key')
end
# String flag
string_flag = launch_darkly_client.variation('string-flag-key', launch_darkly_user, nil)
if string_flag
Bugsnag.add_feature_flag('string-flag-key', string_flag)
else
Bugsnag.clear_feature_flag('string-flag-key')
end
For more information, please see the LaunchDarkly Ruby SDK documentation.
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')
end
# 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')
end
For more information, please see the Split Ruby SDK documentation.