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

EDIT ON GITHUB

Erlang SDK reference

Read time: 2 minutes
Last edited: Nov 19, 2021

Overview

This topic explains the basics of the LaunchDarkly Erlang server-side SDK and how it works.

To learn more, visit our Erlang SDK GitHub repository. The online API docs contain the programmatic definitions of every type and method. Additionally, you can clone and run sample applications using this SDK with Erlang, Elixir, and the Phoenix framework.

Getting started

Follow the steps below to get started using the LaunchDarkly SDK in your Erlang application.

First, you'll need to download the dependency using Rebar:

1{deps, [
2 {ldclient, "1.0.0", {pkg, launchdarkly_server_sdk}}
3]}.

Then add it to your app.src file:

1{applications,
2 [kernel,
3 stdlib,
4 ldclient
5]},

If you use Elixir you can download the dependency using Mix:

1defp deps do
2 [
3 {:ldclient, "~> 1.0.0", hex: :launchdarkly_server_sdk}
4 ]
5end

After you install the SDK dependency, create an instance of the SDK.

Use a single instance

While the Erlang SDK supports starting multiple instances, most use cases only need a single instance. Consider using multiple instances only if you need to simultaneously access more than one environment. Do not start an instance every time you need to make a variation or other SDK call.

Here is an example:

1% This starts an instance with the default options
2ldclient:start_instance("YOUR_SDK_KEY")
3
4% You can also start a named instance
5ldclient:start_instance("YOUR_SDK_KEY", my_instance)

Now you can check which flag variation a specific user should receive:

1Flag = ldclient:variation(<<"YOUR_FLAG_KEY">>, #{key => <<"123">>}, false)

Lastly, shut down the client when your application terminates. To learn more, read Shutting down.

Transport Layer Security (TLS)

The SDK includes configuration options that allow you to set custom TLS options. If you don't set these options, then the SDK will use the Erlang/OTP defaults. The default TLS connection settings in Erlang/OTP do not validate the identity or authenticity of certificates.

If your application has existing TLS options, then you can pass them to the SDK:

1ldclient:start_instance(SdkKey, #{
2 http_options => #{
3 tls_options => YourOptions
4 }}),

The SDK also provides helper methods to create TLS options. We recommend ensuring that the SDK is using a Certificate Authorities (CA) store that is regularly updated for production environments.

Here is a list of helper methods:

  • ldclient_config:tls_basic_options(): This helper provides a basic TLS configuration suitable for development. It tries to use a CA store in the default location for many linux distributions (/etc/ssl/certs/ca-certificates.crt). If it can't find the store, then it will use the store from the certifi package.
  • ldclient_config:tls_basic_linux_options(): This helper provides a basic TLS configuration for linux. It uses the CA store located at /etc/ssl/certs/ca-certificates.crt.
  • ldclient_config:tls_ca_certfile_options(CaStorePath): This helper provides a basic TLS configuration with the CA store you specify.
  • ldclient_config:tls_basic_certifi_options(): This helper provides a basic TLS configuration that uses the certifi store. Because this store is from a dependency of the package, it is not maintained or updated by OS releases.
  • ldclient_config:with_tls_revocation(TlsOptions): This helper extends a TLS configuration with certificate revocation. Revocation is not included in the basic configuration because the Erlang/OTP does not cache revocation results. Enabling this feature incurs additional requests per request the SDK makes.

Supported features

This SDK supports the following features: