No results for ""
EXPAND ALL
  • Home
  • API docs

GIVE DOCS FEEDBACK

Creating new flags

Read time: 8 minutes
Last edited: Apr 08, 2024

Overview

This topic explains how to create new feature flags in LaunchDarkly. You can use feature flags in any aspect of your application, from the customer-facing user interface (UI) to the backend.

The procedures in this topic assume that you have already configured a LaunchDarkly SDK and are ready to use the LaunchDarkly UI.

You must indicate if you are using either mobile or client-side SDKs

By default, flags are only available to server-side SDKs. If you don't check the SDKs using Mobile Key and/or SDKs using client-side ID boxes when creating a flag, then your mobile and client-side SDKs will not be able to evaluate the flag. To learn more, read Making flags available to client-side and mobile SDKs.

In the LaunchDarkly UI, you can create a new flag, clone and modify an existing flag to create new ones, and set default values for flags.

You can use the API instead

Customers on a Pro or Enterprise plan can also use the LaunchDarkly API to create and manage feature flags, as well as do many other tasks. LaunchDarkly is an API-first product, so everything you can do in the LaunchDarkly UI is also available as an API endpoint. To learn more, read the tutorial Using the LaunchDarkly REST API. For complete reference materials, read the API documentation.

Creating a feature flag

You can create and modify feature flags from the flags list. To learn more, read The flags list.

To create a feature flag:

  1. Navigate to the flags list.
  2. Click Create flag.
  3. Enter a unique, human-readable Name.
  4. (Optional) Update the flag Key. You'll use this key to reference the flag in your code. A suggested key auto-populates from the name you enter, but you can customize it if you wish.
Flag keys are important and permanent

Designate flag keys with naming conventions that the SDKs you use support. For example, if your SDK does not use dot notation, you may not want to use dot notation in your flag keys. If you do, LaunchDarkly automatically converts the key to a format your SDK can use, but this can cause collisions if two flags have similar keys. There are configuration options at the SDK level that help you avoid these issues. To learn more, read Flag keys in the React Web SDK.

After you save the flag key, you cannot modify it. You can change a flag's name, however, whenever you want.

  1. (Optional) Enter a Description of the flag. A brief, human-readable description helps your account members understand what the flag is for. Flag descriptions can include Markdown and inline Confluence links. To learn more about LaunchDarkly's integration with Confluence, read Confluence embedded pages.
  2. (Optional) Update the Maintainer for the flag. The maintainer defaults to the flag creator.
  3. (Optional) Check the Include flag in this project's release pipeline box. To learn more, read Release pipelines.
  4. (Optional) Choose any Metrics to monitor in the Metrics section. To learn more, read Metrics.
  5. Choose a flag template in the Configuration section. The options are:
  • Custom: A flag that you can configure exactly how you wish.
  • Release: A temporary flag that initially serves false to all targets, then progressively rolls out to 100%.
  • Kill switch: A permanent flag that enables or disables non-core functionality.
  • Experiment: A flag that you can use to test a hypothesis and improve on your findings.
  • Migration: A temporary flag used to migrate data or systems while keeping your application available.
  1. (Optional) If applicable, follow the instructions for the flag template you chose:
  • For a kill switch, experiment, or release flag, select a Flag variations template:
    • Choose whether the flag is temporary or permanent.
    • Boolean: optionally update the Name of the true and false variations.
    • String: enter a Value for each variation, and optionally update the Name of each variation. To add more variations, click +Add variation.
    • Number: enter a Value for each variation, and optionally update the Name of each variation. To add more variations, click +Add variation.
    • JSON: enter a Value for each variation, and optionally update the Name of each variation. To add more variations, click +Add variation.
  • For a migration flag, choose a two-, four-, or six-stage migration.
  1. (Optional) Update the default variations.
  2. (Optional) Choose one or more tags from the Tags menu.
Tags let you sort flags into groups

Tags are useful for managing flag permissions using custom roles. For example, you can use a specific tag to determine who has read or write access for the flag. To learn more, read Custom roles.

  1. Check the SDKs using Mobile Key and/or SDKs using client-side ID boxes to indicate which client-side SDKs you will use to evaluate this flag. If you are using a server-side SDK, leave these boxes unchecked.
  2. Click Create flag.

The new flag appears in the flags list.

You can also use the REST API: Create a feature flag

Making flags available to client-side and mobile SDKs

By default, flags are only available to server-side SDKs. When you create a flag, you can choose to expose the flag to SDKs which use client-side IDs, SDKs which use mobile keys, or both. If you're using a client-side or mobile SDK, you must expose your feature flags in order for the client-side or mobile SDKs to evaluate them.

Here is an image of the "Client-side SDK availability" section on a flag's Settings tab:

The "Client-side SDK availability" section of a flag's "Settings" tab.
The "Client-side SDK availability" section of a flag's "Settings" tab.

If an SDK tries to evaluate a feature flag that is not available, LaunchDarkly serves the default value for that flag.

To make all of a project's flags available to client-side or mobile SDKs by default, check the SDKs using Client-side ID or SDKs using Mobile key checkboxes in the project's Flags tab.

Security implications of making flags available to mobile SDKs

SDKs for mobile devices use mobile SDK keys, which are readily available to mobile apps. A leaked mobile SDK key allows the holder to circumvent JavaScript's Secure Mode. This can give the holder access to the value of every flag for any context, even without knowing the SDK key that hashes the context key in Secure Mode.

To learn more, read Client-side, server-side, and edge SDKs.

Configuring the same flag in different environments

All environments within a project have the same set of feature flags. When you create a new feature flag, it is created in every environment in your LaunchDarkly project. That flag is scoped to your entire project.

Understanding flag scopes

Flag scoping refers to the parts of LaunchDarkly where a flag is available or used. If a flag is scoped at the project level, it is available to all environments within the project, because projects contain environments. To learn more about projects, read Projects.

To learn more about environments, read Environments.

Flag configuration settings are specific to each environment. The changes you make in one environment do not apply to the same flag in any other environment. If you want to, you can configure the same flag in a unique way for every environment you have.

To configure a flag in a different environment:

  1. Navigate to the flags list.
  2. Click the environment name in the top left corner. The "Switch environment" menu appears:
The "Switch environment" menu.
The "Switch environment" menu.
  1. Search for the environment you wish to switch to and click on it, or choose it from the list. The flags list for the new environment appears.
Look for the header change

You know you're in a different environment because the name displayed in the top left corner changes when you select that environment from the list.

  1. Find the flag you wish to modify and make whatever changes you like.

Setting default values

When you create a feature flag, some of its variations are designated as default values. You can accept the defaults or change them. When you change default values for a new flag, LaunchDarkly creates the flag across all environments in your project with the new variations set as its default on and off values.

The default variations when creating a flag.
The default variations when creating a flag.

To learn more about default flag values, read Changing default flag values.

You can enforce project-level default flag settings

You can optionally configure default flag settings for a project, which LaunchDarkly will apply to any new flags you create within that project. To learn how, read Flag templates.

Cloning flags

Cloning flags is a Pro and Enterprise feature

Cloning flags is available to customers on a Pro or Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.

You can create new flags by cloning existing flags. When you clone a flag, LaunchDarkly makes a new flag and copies the original flag's targeting configuration for all environments, including default values and whether the flag is toggled on or off. You can then modify the clone's configuration if needed.

To clone a flag:

  1. Navigate to the flags list.
  2. Find the flag you wish to clone and click its name. The flag's Targeting tab appears.
  3. Click the flag's Settings tab.
  4. In the "Clone flag" section, click Clone this flag.
  5. The "Clone feature flag" dialog appears:
The "Clone feature flag" dialog.
The "Clone feature flag" dialog.
  1. Enter a unique, human-readable Name.
  2. Enter a unique flag Key. You'll use this key to reference the flag in your code. A suggested key auto-populates from the name you enter, but you can customize it if you wish.
  3. (Optional) Enter a Description of the new flag. A brief, human-readable description helps your account members understand what the flag is for.
  4. (Optional) Click into the Tags menu and choose one or more tags for your flag.
Tags sort flags into groups

Tags are useful for managing flag permissions using custom roles. For example, you can tag a flag as "Marketing" and "DevOps," and then use these tags to determine who has read or write access for the flag. To learn more, read Custom roles.

  1. Click Save flag. You are taken to the new flag's details page.

The new flag appears in the flags list.

You can also use the REST API: Copy feature flag