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

Configuration

Read time: 20 minutes
Last edited: Nov 15, 2024

Overview

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.

Newer versions of LaunchDarkly SDKs replace users with contexts

A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: "users." To learn more, read Contexts.

Creating contexts and evaluating flags based on them is supported in the latest major versions of most of our SDKs. For these SDKs, the code samples on this page include the two most recent versions.

Customize the SDK

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:

  • Client-side SDKs
  • Server-side SDKs
  • Edge SDKs

Client-side SDKs

This feature is available in the following client-side SDKs:

.NET (client-side)

Expand .NET (client-side) code sample
The .NET (client-side) SDK uses a mobile key

The .NET (client-side) SDK uses a mobile key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read Configuration.

Android

Expand Android code sample
The Android SDK uses a mobile key

The Android SDK uses a mobile key. Keys are specific to each project and environment. They are available from the Environments list for each project. To learn more about key types, read Keys.

This code sample shows you how to configure the client connect and flush interval parameters:

To learn more about the specific configuration options available in this SDK, read LDConfig.Builder.

C++ (client-side)

Expand C++ (client-side) code sample
The C++ (client-side) SDK uses a mobile key

The C++ (client-side) SDK uses a mobile key. Keys are specific to each project and environment. They are available from the Environments list for each project. To learn more about key types, read Keys.

This code sample shows you how to configure the event queue capacity and flush interval parameters:

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.

Electron

Expand Electron code sample
The Electron SDK uses a client-side ID

The Electron SDK uses a client-side ID. Client-side IDs are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read LDOptions.

Flutter

Expand Flutter code sample
The Flutter SDK uses a mobile key or client-side ID

The Flutter SDK version 4 uses either a mobile key or a client-side ID, depending on the platform that you build for. If you are building for Windows, Mac, Linux, Android, or iOS, you must use a mobile key. If you are building for a web browser, you must use a client-side ID.

Your environment's mobile key and client-side ID are specific to each project and environment. They are both available from the Environments list for each project. To learn more about key types, read Keys.

The Flutter SDK version 3 and earlier requires a mobile key, as it only works on mobile platforms.

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.

iOS

Expand iOS code sample
The iOS SDK uses a mobile key

The iOS SDK uses a mobile key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read LDConfig.

JavaScript

Expand JavaScript code sample
The JavaScript SDK uses a client-side ID

The JavaScript SDK uses a client-side ID. Client-side IDs are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read LDOptions.

Node.js (client-side)

Expand Node.js (client-side) code sample
The Node.js (client-side) SDK uses a client-side ID

The Node.js (client-side) SDK uses a client-side ID. Client-side IDs are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read LDOptions.

React Native

Expand React Native code sample
The React Native SDK uses a mobile key

The React Native SDK uses a mobile key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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.

Always include a timeout parameter in v9 and earlier when calling configure

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:

To learn more about the specific configuration options available in this SDK, read LDOptions.

Roku

Expand Roku code sample
The Roku SDK uses a mobile key

The Roku SDK uses a mobile key. Keys are specific to each project and environment. They are available from the Environments list for each project. To learn more about key types, read Keys.

This code sample shows you how to create a configuration object:

We support the following configuration options for both SceneGraph and non-SceneGraph usage:

Server-side SDKs

This feature is available for the following server-side SDKs:

.NET (server-side)

Expand .NET (server-side) code sample
The .NET (server-side) SDK uses an SDK key

The .NET (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration that are available in this SDK, read ConfigurationBuilder.

Apex

Expand Apex code sample

This code sample shows you how to configure the client to redact all user attributes in events:

To learn more about the specific configuration options available for this SDK, read LDConfig.Builder.

C++ (server-side)

Expand C++ (server-side) code sample
The C++ (server-side) SDK uses an SDK key

The C++ (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. To learn more about key types, read Keys.

This code sample shows you how to configure the event queue capacity and flush interval parameters:

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.

Erlang

Expand Erlang code sample
The Erlang SDK uses an SDK key

The Erlang SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available for this SDK, read ldclient_config.

Go

Expand Go code sample
The Go SDK uses an SDK key

The Go SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available for this SDK, read Config.

Haskell

Expand Haskell code sample
The Haskell SDK uses an SDK key

The Haskell SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration properties that are available in this SDK, read Config.

Java

Expand Java code sample
The Java SDK uses an SDK key

The Java SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration properties that are available in this SDK, read LDConfig.Builder.

Lua

Expand Lua code sample
The Lua SDK uses an SDK key

The Lua SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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.

Finish setting up your configuration client before you call LDClientInit

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:

To learn more about the specific configuration properties that are available in this SDK, read clientInit.

Node.js (server-side)

Expand Node.js (server-side) code sample
The Node.js (server-side) SDK uses an SDK key

The Node.js (server-side) SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read LDOptions.

PHP

Expand PHP code sample
The PHP SDK uses an SDK key

The PHP SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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.

Sending events in PHP

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:

To learn more about the specific configuration options available in this SDK, read the SDK API documentation for the LDClient constructor.

Python

Expand Python code sample
The Python SDK uses an SDK key

The Python SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read ldclient.config.

Ruby

Expand Ruby code sample
The Ruby SDK uses an SDK key

The Ruby SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read Config.

Rust

Expand Rust code sample
The Rust SDK uses an SDK key

The Rust SDK uses an SDK key. Keys are specific to each project and environment. They are available from the Environments list for each project. 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:

To learn more about the specific configuration options available in this SDK, read Config.

Edge SDKs

This feature is available in the following edge SDKs:

Akamai

Expand Akamai code sample
The Akamai SDK uses a client-side ID

The Akamai SDK uses a client-side ID. Client-side IDs are specific to each project and environment. They are available from the Environments list for each project. 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 Akamai SDK only supports the logger configuration option.

To learn more about the specific configuration options available in this SDK, read LDOptions.

Cloudflare

Expand Cloudflare code sample
The Cloudflare SDK uses a client-side ID

The Cloudflare SDK uses a client-side ID. Client-side IDs are specific to each project and environment. They are available from the Environments list for each project. 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.

To learn more about the specific configuration options available in this SDK, read the SDK's API docs.

Vercel

Expand Vercel code sample
The Vercel SDK uses a client-side ID

The Vercel SDK uses a client-side ID. Client-side IDs are specific to each project and environment. They are available from the Environments list for each project. 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.

To learn more about the specific configuration options available in this SDK, read LDOptions.