This topic explains how to configure various LaunchDarkly SDKs. It gives code samples for each SDK that include different configuration examples. This feature is available for client-side, server-side, and edge SDKs.
You can use the configuration feature to configure certain aspects of your SDK, including flush intervals, timeout periods, and client connect parameters.You can disable the publication of events for testing purposes. We strongly recommend against disabling events for any other reason because many features depend on regularly receiving analytics events, including targeting rules, flag statuses, and the Contexts or Users lists. To learn more, read Analytics events.Details about each SDK’s configuration are available in the SDK-specific sections below:
The .NET (client-side) SDK uses a mobile key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to create a custom configuration object to pass custom parameters to the client. With it, we’ve configured the event queue flush frequency.You can configure Configuration.Builder:
The Android SDK uses a mobile key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
In the Android SDK, most of the configuration properties are grouped into areas of functionality, each of which has its own builder class that is only available if you are using that functionality. The basic areas of functionality are data source, events, networking, and service URIs.This code sample shows you how to configure the client connect and flush interval parameters:
The C++ (client-side) SDK uses a mobile key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to configure the event queue capacity and flush interval parameters:
auto config_builder = client_side::ConfigBuilder("example-mobile-key"); config_builder.Events() .Capacity(1000) .FlushInterval(std::chrono::seconds(30)); auto config = config_builder.Build(); if (!config) { /* an error occurred, config is not valid */ }
To learn more about the specific configuration options available in this SDK, read ConfigBuilder. To learn more about the event queue capacity and flush interval parameters specifically, read EventsBuilder.
The Electron SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in client-side code. Do not embed a server-side SDK key in a client-side application. You can find client-side IDs and project keys in Project settings, on the Environments list. To learn more about key types, read Keys.If you connect the Electron SDK to the ldcli dev-server for local testing, use your project key instead of a client-side ID. Set all service endpoints to http://localhost:8765. If you use a client-side ID, the SDK connects to LaunchDarkly rather than the dev-server, which can produce CORS errors (especially from the renderer process).
This code sample shows you how to create a custom configuration object to pass custom parameters to the client:
The Flutter SDK v4 uses either a mobile key or a client-side ID, depending on your target platform. For Windows, macOS, Linux, Android, or iOS, use a mobile key. For web builds, use a client-side ID.You can find client-side IDs, mobile keys, and project keys in Project settings on the Environments list. To learn more about key types, read Keys.If you connect a Flutter web app to the ldcli dev-server for local testing, use your project key instead of a client-side ID, and set all service endpoints to http://localhost:8765. If you use a mobile key or client-side ID, the app connects to LaunchDarkly rather than the dev-server, which can result in CORS errors.
The Flutter SDK version 4 uses either a mobile key or a client-side ID, depending on the platform that you build for. You can set these in the LAUNCHDARKLY_MOBILE_KEY and LAUNCHDARKLY_CLIENT_SIDE_ID environment variables, and then use the CredentialSource helper to select your credential and provide it to your configuration. CredentialSource expects one of the two environment variables to be set, but not both.This code sample shows you how to configure the credential, automatic environment attributes, and evaluation reasons options:
The credential and automatic environment attributes configuration options are required. All other configuration options are optional and use default values if not set.To learn more about the specific configuration options available in this SDK, read LDConfig.
The iOS SDK uses a mobile key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to configure the client connection timeout and event flush interval parameters:
The JavaScript SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in client-side code. Do not embed a server-side SDK key in a client-side application. You can find client-side IDs and project keys in Project settings, on the Environments list. To learn more about key types, read Keys.If you connect the JavaScript SDK to the ldcli dev-server for local testing, use your project key instead of a client-side ID. Set all service endpoints to http://localhost:8765. If you use a client-side ID, the SDK connects to LaunchDarkly rather than the dev-server, which can result in CORS errors.
This code sample shows you how to create a custom configuration object to pass custom parameters to the client:
Version 4.0 of the JavaScript SDK does not use the initialize method from earlier versions. To learn more, read Client initialization.
The Node.js (client-side) SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in client-side code. Do not embed a server-side SDK key in a client-side application. You can find client-side IDs and project keys in Project settings, on the Environments list. To learn more about key types, read Keys.If you connect the Node.js (client-side) SDK to the ldcli dev-server for local testing, use your project key instead of a client-side ID. Set all service endpoints to http://localhost:8765. If you use a client-side ID, the SDK connects to LaunchDarkly rather than the dev-server, which can result in CORS errors.
This code sample shows you how to create a custom configuration object to pass custom parameters to the client:
const options = { flushInterval: 10000, // milliseconds allAttributesPrivate: true }; const client = LDClient.initialize('example-client-side-id', context, options); try { await client.waitForInitialization(5); // initialization succeeded, flag values are now available } catch (err) { // initialization failed or did not complete before timeout }
To learn more about the specific configuration options available in this SDK, read LDOptions.
The React Native SDK uses a mobile key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to create a configuration object to pass configuration parameters to the client.The configuration object can include a variety of options. In version 10 of the SDK, all properties are optional.In versions 9 and earlier, mobileKey was a required property, but all other properties were optional. Additionally, in versions 9 and earlier we recommend setting a timeout parameter when you call configure. If the client receives flag values before the timeout, the returned promise will resolve. Otherwise, it will be rejected.
In versions 9 and earlier, do not configure your SDK to initialize without a timeout parameter. Doing so will cause your app never to load if there is a connectivity problem. We recommend setting a timeout for no more than 1-5 seconds. To learn more, read React Native SDK reference.
Here is an example:
import { type LDOptions } from '@launchdarkly/react-native-client-sdk'; const options = { withReasons: true, }; const client = new ReactNativeLDClient('example-mobile-key', AutoEnvAttributes.Enabled, options);
To learn more about the specific configuration options available in this SDK, read LDOptions.
The Roku SDK uses a mobile key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to create a configuration object:
' for a legacy Roku application config = LaunchDarklyConfig("example-mobile-key") ' for a SceneGraph Roku Application config = LaunchDarklyConfig("example-mobile-key", CLIENT_SCENEGRAPH_NODE)
We support the following configuration options for both SceneGraph and non-SceneGraph usage:
The .NET (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object:
var config = Configuration.Builder("YOUR_SDK_KEY") .Events( Components.SendEvents().FlushInterval(TimeSpan.FromSeconds(2)) ) .StartWaitTime(TimeSpan.FromSeconds(5)) .Build(); var client = new LdClient(config);
To learn more about the specific configuration that are available in this SDK, read ConfigurationBuilder.
The C++ (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to configure the event queue capacity and flush interval parameters:
auto config_builder = server_side::ConfigBuilder("YOUR_SDK_KEY"); config_builder.Events() .Capacity(1000) .FlushInterval(std::chrono::seconds(30)); auto config = config_builder.Build(); if (!config) { /* an error occurred, config is not valid */ }
To learn more about the specific configuration options available for this SDK, read ConfigBuilder. To learn more about the event queue capacity and flush interval parameters specifically, read EventsBuilder.
The Erlang SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters when the client starts with the Options map parameter. The code in this example turns off streaming, so the SDK connects to LaunchDarkly through polling.To pass custom parameters:
% Specify options ldclient:start_instance("YOUR_SDK_KEY", #{stream => false}) % With a custom instance name ldclient:start_instance("YOUR_SDK_KEY", your_instance, #{stream => false})
To learn more about the specific configuration options available for this SDK, read ldclient_config.
The Go SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object. The code in this sample configures the event flush interval parameter.To pass custom parameters:
The Haskell SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object. This example configures the event queue capacity and flush interval parameters.To pass custom parameters:
The Java SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.In this example, we’ve configured two properties for HTTP (the connect and socket timeouts), and one property for analytics events (the event flush interval).To pass custom parameters:
The Lua SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.
You must finish setting up your configuration object before you call clientInit. If you initialize the client before configuration is complete, the SDK will not use anything you provide after initialization.
Here, we’ve configured the event queue capacity and flush interval parameters:
local config = { events = { capacity = 1000, flushIntervalMilliseconds = 30000 } } -- This blocks for 1 second to initialize local client = ld.clientInit("YOUR_SDK_KEY", 1000, config)
To learn more about the specific configuration properties that are available in this SDK, read clientInit.
The Node.js (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object:
import * as ld from '@launchdarkly/node-server-sdk'; const options: ld.LDOptions = { timeout: 3, }; const client = ld.init('YOUR_SDK_KEY', options);
To learn more about the specific configuration options available in this SDK, read LDOptions.
The PHP SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample uses the cache option, which passes as an array to the client constructor. There are a few additional options you can set in this array.We’ve set the client connect timeout to three seconds in addition to providing a custom cache storage provider.
The LaunchDarkly SDK sends data back to our server to record events from track and variation calls. On our other platforms, this data is sent asynchronously, so that it adds no latency to serving web pages. PHP’s shared-nothing architecture makes this difficult.By default, LaunchDarkly forks an external process that executes curl to send this data. In practice, we’ve found that this is the most reliable way to send data without introducing latency to page load times. If your server does not have curl installed, or has other restrictions that make it impossible to invoke curl as an external process, you may need to implement a custom EventProcessor to send events to LaunchDarkly.
Here is an example:
$client = new LaunchDarkly\LDClient("YOUR_SDK_KEY", ["cache" => $cacheStorage, "connect_timeout" => 3]);
To learn more about the specific configuration options available in this SDK, read the SDK API documentation for the LDClient constructor.
The Python SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object:
The Ruby SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to configure the behavior of the client by creating a custom configuration object.The client constructor takes a configuration object as an optional parameter. In this example, we’ve set the connection timeout to LaunchDarkly to one second, and the read timeout to two seconds.To create a custom configuration object:
The Rust SDK uses an SDK key. Keys are specific to each project and environment. They are available from Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object:
let config = ConfigBuilder::new("YOUR_SDK_KEY") .offline(true) .build(); let client = Client::build(config).unwrap();
To learn more about the specific configuration options available in this SDK, read Config.
The Akamai SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in edge code. Do not embed a server-side SDK key in an edge application.You can find client-side IDs in Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.
The Cloudflare SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in edge code. Do not embed a server-side SDK key in an edge application.You can find client-side IDs in Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.Versions 1 and 2 of the Cloudflare SDK only support the logger configuration option. Versions 2.3.0 and later also support an events configuration option.
The Fastly SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in edge code. Do not embed a server-side SDK key in an edge application.You can find client-side IDs in Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.
import { KVStore } from 'fastly:kv-store'; import { init, LDOptions } from '@launchdarkly/fastly-server-sdk'; const KV_STORE_NAME = 'launchdarkly'; const EVENTS_BACKEND_NAME = 'launchdarkly'; const store = new KVStore(KV_STORE_NAME); async function handleRequest(event: FetchEvent) { const ldClient = init('example-client-side-id', store, { eventsBackendName: EVENTS_BACKEND_NAME, }); await ldClient.waitForInitialization(); ... }
To learn more about the specific configuration options available in this SDK, read FastlySDKOptions.
The Vercel SDK requires a client-side ID. Client-side IDs are specific to each project and environment. They are not secret, and you can include them in edge code. Do not embed a server-side SDK key in an edge application.You can find client-side IDs in Project settings, on the Environments list. To learn more about key types, read Keys.
This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.Version 1 of the Vercel SDK only supports the logger configuration option. Versions 1.2.0 and later also support an events configuration option.