Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for feature flags #758

Merged
merged 24 commits into from
Dec 1, 2022
Merged

Add support for feature flags #758

merged 24 commits into from
Dec 1, 2022

Conversation

imjoehaines
Copy link
Contributor

Goal

This PR adds support for feature flags to Bugsnag-ruby

The new APIs are available on both the Bugsnag module and invidiual events (via on_error callbacks):

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

This returns true if:

- name is a string with at least 1 character
- variant is nil OR variant is a string
The FeatureFlagDelegate now ensures flags are valid before storing them,
so we no longer deliver flags with invalid names
This allows users to add feature flags to Bugsnag whenever they interact
with their feature flag service, e.g.

```ruby
flag = get_flag_from_service('new-login-page')

if flag.enabled?
  Bugsnag.add_feature_flag('new-login-page')
  # render new login page
else
  Bugsnag.clear_feature_flag('new-login-page')
  # render old login page
end
```

The previous implementation relied on event's already being request
specific, but meant feature flags would usually have to be added in an
on_error callback
Now that the implementations of add_/clear_feature_flag(s) are the same,
we can use a module to implement these methods and save us from having
copy pasted methods/docs in 3 places
This embeds methods from included modules directly into the class' docs,
rather than linking to them separately

This makes the docs a lot clearer when a class includes some methods
from a module as they are now listed next to every other method
@imjoehaines imjoehaines merged commit c203e85 into next Dec 1, 2022
@imjoehaines imjoehaines deleted the integration/feature-flags branch December 1, 2022 09:56
@imjoehaines imjoehaines mentioned this pull request Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants