LaunchDarkly
The LaunchDarkly provider contains support for LaunchDarkly's feature flags.
The @flags-sdk/launchdarkly package provides
- An adapter for loading flags from LaunchDarkly.
- A
getProviderDatafunction for use with the Flags Explorer
Learn more about Adapters
Learn more about the Flags Explorer
Setup
The LaunchDarkly provider is available in the @flags-sdk/launchdarkly module. Install it with
Provider instance
Import the default adapter instance ldAdapter from @flags-sdk/launchdarkly:
If you need a customized setup, you can import createLaunchDarklyAdapter from @flags-sdk/launchdarkly and create an adapter instance with your settings:
| Option key | Type | Description |
|---|---|---|
projectSlug | string | LaunchDarkly project slug |
clientSideId | string | LaunchDarkly client-side ID |
globalConfigConnectionString | string | Global Config connection string |
The default LaunchDarkly adapter configures itself based on the following environment variables:
LAUNCHDARKLY_CLIENT_SIDE_ID(required) →clientSideIdLAUNCHDARKLY_PROJECT_SLUG(required) →projectSlugEXPERIMENTATION_CONFIG(required) →globalConfigConnectionString
The native LaunchDarkly Marketplace integration exposes the Global Config connection string as EXPERIMENTATION_CONFIG when Global Config is enabled for the collection.
If you use the legacy LaunchDarkly Vercel integration, which provides the connection string as GLOBAL_CONFIG, set EXPERIMENTATION_CONFIG to the same value, or use createLaunchDarklyAdapter to pass globalConfigConnectionString explicitly.
Identify users
LaunchDarkly relies on a LaunchDarkly Evaluation Context object to evaluate the flags for a given request.
Use the identify function to determine a LaunchDarkly Evaluation Context.
Learn more about dedupe
Learn more about identify
Methods
The LaunchDarkly adapter provides a method for evaluating flags.
variation
The identify function must return the Evaluation Context.
ldClient
The adapter exposes the LaunchDarkly client it uses internally through the ldClient property.
Global Config
The LaunchDarkly adapter loads the configuration from Global Config.
Global Config is a global, ultra-low latency store which uses active replication and is specifically designed for serving feature flag configuration.
The default LaunchDarkly adapter, exported as ldAdapter, will automatically connect to Global Config when the required environment variables are set. It reads the connection string from EXPERIMENTATION_CONFIG (provided by the native Marketplace integration).
Caveats
Initializing
The Flags SDK automatically initializes the LaunchDarkly client when a flag is evaluated.
If you want to initialize the LaunchDarkly client before the first flag is used, you can call ldAdapter.ldClient.waitForInitialization() manually.
LaunchDarkly Vercel SDK
The adapter uses the LaunchDarkly Vercel SDK (@launchdarkly/vercel-server-sdk) internally, which is designed for usage with Global Config.
Flags Explorer
View and override your LaunchDarkly flags using the Flags Explorer.
To make Flags Explorer aware of your LaunchDarkly flags, you need to provide a route which Flags Explorer will load your flags metadata from.
Use the getProviderData function in your Flags API endpoint to load and emit your LaunchDarkly data. Accepts an options object with the following keys.
| Options key | Type | Description |
|---|---|---|
apiKey | string | LaunchDarkly API Key |
environment | string | LaunchDarkly environment |
projectKey | string | LaunchDarkly project key |
Read more
Read more about LaunchDarkly, Flags SDK, and the LaunchDarkly adapter.
Learn more about the Flags Explorer