• HOME
  • INTEGRATIONS
  • SDKS
  • GUIDES
  • API DOCS
No results for ""
EXPAND ALL
launchdarkly.com

EDIT ON GITHUB

Configuration

Read time: 5 minutes
Last edited: Jun 18, 2021

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 both client-side and server-side SDKs.

Customizing 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, but we strongly recommend against it. Many features such as targeting rules, flag statuses, and the Users dashboard depend on regularly receiving analytic events.

Details about each SDK's configuration are available in the SDK-specific sections below.

  • Client-side SDKs
  • Server-side SDKs

Client-side SDKs

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

Android

This code sample shows you how to configure the client connect and flush interval parameters. To learn more about the specific configuration options that are available in this SDK, read the Javadoc.

1LDConfig ldConfig = new LDConfig.Builder()
2 .setMobileKey("YOUR_MOBILE_KEY")
3 .setConnectionTimeoutMillis(5000)
4 .setEventsFlushIntervalMillis(5000)
5 .build();

C/C++ (client-side)

This code sample shows you how to configure the event queue capacity and flush interval parameters. To learn more about the specific configuration options that are available in this SDK, read the SDK's API docs.

1struct LDConfig *config = LDConfigNew("YOUR_MOBILE_KEY");
2LDConfigSetEventsCapacity(config, 1000);
3LDConfigSetEventsFlushIntervalMillis(config, 30000);

Flutter

This code sample shows you how to configure the client connect and flush interval parameters. To learn more about the specific configuration options that are available in this SDK, read the SDK's API docs.

1LDConfig ldConfig = LDConfigBuilder('YOUR_MOBILE_KEY')
2 .setConnectionTimeoutMillis(5000)
3 .setEventsFlushIntervalMillis(5000)
4 .build();

iOS

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 that are available in this SDK, read the SDK's API docs.

1LDConfig *ldConfig = [[LDConfig alloc] initWithMobileKey:@"YOUR_MOBILE_KEY"];
2ldConfig.connectionTimeout = 10.0;
3ldConfig.eventFlushInterval = 30.0;

JavaScript

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 that are available in this SDK, read the SDK's API docs.

1var ldclient = LDClient.initialize('YOUR_CLIENT_SIDE_ID', user, options = {
2 allAttributesPrivate: true
3});

Node.js (client-side)

This code sample shows you how to create a custom configuration object to pass custom parameters to the client. For a full guide to the available configuration options, read LDOptions in the TypeScript reference.

1const options = {
2 flushInterval: 10000,
3 allAttributesPrivate: true
4};
5
6const ldClient = LaunchDarkly.initialize('YOUR_CLIENT_SIDE_ID', user, options);

React Native

This code sample shows you how to create a custom configuration object to pass custom parameters to the client.

The config object can include a variety of options. mobileKey is a required property, but all other properties are optional.

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

1let config =
2 { "mobileKey": "YOUR_MOBILE_KEY",
3 "connectionTimeoutMillis": 3000
4 };
5await client.configure(config, user);

Roku

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

1REM for a legacy Roku application
2config = LaunchDarklyConfig("YOUR_MOBILE_KEY")
3
4REM for a SceneGraph Roku Application
5config = LaunchDarklyConfig("YOUR_MOBILE_KEY", CLIENT_SCENEGRAPH_NODE)

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

1config.setAppURI(String)
2
3config.setEventsURI(String)
4
5config.setStreamURI(String)
6
7
8config.setPollingIntervalSeconds(Integer)
9
10config.setOffline(Boolean)
11
12
13config.addPrivateAttribute(String)
14
15config.setAllAttributesPrivate(Boolean)
16
17
18config.setEventsCapacity(Integer)
19
20config.setEventsFlushIntervalSeconds(Integer)
21
22config.setStreaming(Boolean)

Xamarin

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 that are available in this SDK, read the SDK's API docs.

1Configuration config = LaunchDarkly.Client.Configuration
2 .Builder("YOUR_SDK_KEY")
3 .EventFlushInterval(TimeSpan.FromSeconds(2))
4 .Build();
5LdClient ldClient = LdClient.Init(config, user);

Server-side SDKs

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

.NET

This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

For a complete list of configuration options for the client, including proxy settings, timeouts, and streaming/polling options, read the SDK's API documentation for ConfigurationBuilder.

1var config = Configuration.Builder("YOUR_SDK_KEY")
2 .Events(
3 Components.SendEvents().FlushInterval(TimeSpan.FromSeconds(2))
4 )
5 .Build();
6var ldClient = new LdClient(config);

Apex

This code sample shows you how to configure the client to redact all user attributes in events. To learn more about the configuration options available for this SDK, read the SDK's API docs.

1LDConfig config = new LDConfig.Builder()
2 .setAllAttributesPrivate(true)
3 .build();

C/C++ (server-side)

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

Finish setting up your configuration client before you call `LDClientInit`

You must finish setting up your configuration object before you call LDClientInit. If you initialize the client before configuration is complete, the SDK will not use anything you provide after initialization.

For a complete list of configuration options, read the SDK's API docs.

1struct LDConfig *config = LDConfigNew("YOUR_SDK_KEY");
2LDConfigSetEventsCapacity(config, 1000);
3LDConfigSetEventsFlushInterval(config, 30000);

Erlang

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.

% Specify options
ldclient:start_instance("YOUR_SDK_KEY", #{stream => false})

% With a custom instance name
ldclient:start_instance("YOUR_SDK_KEY", my_instance, #{stream => false})

Go

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 learn more about the configuration options, read Config.

1import (
2 ld "gopkg.in/launchdarkly/go-server-sdk.v5"
3 "gopkg.in/launchdarkly/go-server-sdk.v5/ldcomponents"
4)
5
6var config ld.Config
7
8config.Events = ldcomponents.SendEvents().FlushInterval(10 * time.Second)
9
10ldClient := ld.MakeCustomClient("YOUR_SDK_KEY", config, 5 * time.Second)

Haskell

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 learn more about the specific user properties that are available in this SDK, read the SDK's API docs.

1{-# LANGUAGE OverloadedStrings #-}
2
3import LaunchDarkly.Server.Config
4
5import Data.Function ((&))
6
7config :: Config
8config = (makeConfig "YOUR_SDK_KEY")
9 & configSetEventsCapacity 1000
10 & configSetFlushIntervalSeconds 30

Java

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).

For a complete list of configuration options for the client, including proxy settings, timeouts, and streaming/polling options, read the Javadoc for LDConfig.Builder. You can also read the 4.x version.

1LDConfig config = new LDConfig.Builder()
2 .http(
3 Components.httpConfiguration()
4 .connectTimeout(Duration.ofSeconds(3))
5 .socketTimeout(Duration.ofSeconds(3))
6 )
7 .events(
8 Components.sendEvents()
9 .flushInterval(Duration.ofSeconds(10))
10 )
11 .build();
12LDClient ldClient = new LDClient("YOUR_SDK_KEY", config);

Lua

This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

Here, we've configured the event queue capacity and flush interval parameters.

Finish setting up your configuration client before you call `LDClientInit`

You must finish setting up your configuration object before you call LDClientInit. If you initialize the client before configuration is complete, the SDK will not use anything you provide after initialization.

To learn more about configuration options, read the SDK's API docs.

1local config = {
2 key = YOUR_SDK_KEY,
3 eventsCapacity = 1000,
4 eventsFlushInterval = 30000
5}
6
7local client = ld.clientInit(config, 1000)

Node.js (server-side)

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 that are available in this SDK, read the SDK's API docs.

1var config = {"timeout": 3};
2ldClient = LaunchDarkly.init("YOUR_SDK_KEY", config);

PHP

This code sampel 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.

For a complete list of customizable parameters, read the documentation for the LDClient constructor.

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.

1$client = new LaunchDarkly\LDClient("YOUR_SDK_KEY", array("cache" => $cacheStorage, "connect_timeout" => 3));

Python

This code sample shows you how to pass custom parameters to the client by creating a custom configuration object.

The Config type lets you specify a variety of options. To learn more about the specific configuration options that are available in this SDK, read the SDK's API docs.

1config = Config(sdk_key='YOUR_SDK_KEY', http=HTTPConfig(connect_timeout=5))
2ldclient.set_config(config)

Ruby

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 learn more about the specific configuration options that are available in this SDK, read the SDK's API docs.

1config = LaunchDarkly::Config.new({connect_timeout: 1, read_timeout: 1})
2ld_client = LaunchDarkly::LDClient.new("YOUR_SDK_KEY", config)