• Home
  • Integrations
  • SDKs
  • Guides
  • API docs
    No results for ""
    EXPAND ALL

    EDIT ON GITHUB

    Your first feature flag

    Read time: 5 minutes
    Last edited: Apr 19, 2023

    Overview

    This topic explains how to create 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.

    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. The "Create a feature flag" panel appears:
    The flags list, with the "Create flag" button called out.
    The flags list, with the "Create flag" button called out.
    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.
    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.

    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) Click into the Tags menu and choose one or more tags for your flag.
    Tags let you 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. (Optional) In the "Client-side SDK flag availability" section, check the SDKs using Mobile Key and/or SDKs using client-side ID boxes to designate which SDKs the flag should be available to. To learn more, read Making flags available to client-side and mobile SDKs.
    2. Choose an option in the Flag variations menu. To learn more, read Flag variations.
    3. (Optional) Specify details for your Variation. To learn more, read Understanding multivariate flags.
    4. (Optional) Change the Default values for the flag's on and off states. To learn more, read Setting default values.
    5. (Optional) Select the This is a permanent flag box.
    6. Click Save flag.
    The "Create a feature" flag panel.
    The "Create a feature" flag panel.

    You just created a feature flag. It appears in the 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:

    The "Client-side SDK availability" section of the flag creation panel.
    The "Client-side SDK availability" section of the flag creation panel.

    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 Flag defaults 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 and server-side 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 and click Save flag, the flag is created across all environments in your project with the new variations set as its default on and off values.

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

    You can set project-level flag defaults

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

    Here is a screenshot of flag creation panel:

    The default value options on the flag creation panel.
    The default value options on the flag creation panel.

    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. Click Clone this flag:
    The "Clone this flag" button.
    The "Clone this flag" button.
    1. The "Clone feature flag" panel appears:
    The "Clone feature flag" panel.
    The "Clone feature flag" panel.
    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 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 also appears in the flags list, where you can search for it or access it any time.

    You can also use the REST API: Copy feature flag