For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Sign inTry it free
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
DocsGuidesSDKsIntegrationsAPI docsTutorialsFlagship blog
  • SDKs
    • SDK concepts
    • SDK features
    • Client-side SDKs
    • Server-side SDKs
      • .NET SDK reference
      • Apex SDK reference
      • C++ SDK reference
      • Erlang SDK reference
        • Erlang (server-side) SDK 2.x to 3.0 migration guide
        • Erlang (server-side) SDK 1.x to 2.0 migration guide
      • Go SDK reference
      • Haskell SDK reference
      • Java SDK reference
      • Lua SDK reference
      • Node.js SDK reference
      • PHP SDK reference
      • Python SDK reference
      • Ruby SDK reference
      • Rust SDK reference
    • AI SDKs
    • Edge SDKs
    • OpenFeature providers
    • Observability SDKs
    • Relay Proxy
Sign inTry it free
LogoLogo
On this page
  • Overview
  • Get started
  • Initialize the client
  • Evaluate a context
  • Transport Layer Security (TLS)
  • Shut down the client
  • Supported features
SDKsServer-side SDKs

Erlang SDK reference

Was this page helpful?
Previous

Erlang (server-side) SDK 2.x to 3.0 migration guide

Next
Built with
Recent major versions

Version 3 of the Erlang SDK requires Gun 2.x. To learn more about upgrading, read Erlang (server-side) SDK 2.x to 3.0 migration guide.

Overview

This topic documents how to get started with the Erlang SDK, and links to reference information on all of the supported features.

SDK quick links

LaunchDarkly’s SDKs are open source. In addition to this reference guide, we provide source, API reference documentation, and sample applications:

ResourceLocation
SDK API documentationSDK API docs
Supported SDK VersionsErlang server SDK
GitHub repositoryerlang-server-sdk
Sample applicationsErlang
Elixir
Phoenix
Published moduleHex

Get started

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

First, download the dependency using Rebar:

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

Then, add it to your app.src file:

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

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

Elixir
1defp deps do
2 [
3 {:ldclient, "~> 3.0.0", hex: :launchdarkly_server_sdk}
4 ]
5end
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 on the SDK keys page under Settings. To learn more about key types, read Keys.

Initialize the client

After you install the SDK dependency, create an instance of the client. Specify your SDK key here to authorize your application to connect to a particular environment within LaunchDarkly.

Use a single instance

The Erlang SDK supports starting multiple instances, but 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:

Erlang
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", your_instance)

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

Evaluate a context

Next, check which flag variation a specific context should receive:

1Flag = ldclient:variation(<<"example-flag-key">>, #{key => <<"example-context-key">>}, false)

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:

Erlang
1 ldclient: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.

Shut down the client

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

Supported features

This SDK supports the following features:

  • Anonymous contexts and users
  • Configuration, including
    • Application metadata configuration
    • Service endpoint configuration
  • Context configuration
  • Evaluating flags
  • Flag evaluation reasons
  • Getting all flags
  • Identifying and changing contexts
  • Offline mode
  • Private attributes
  • Reading flags from a file
  • Relay Proxy configuration
    • Using proxy mode
    • Using daemon mode
  • Sending custom events
  • Shutting down
  • Storing data
  • Test data sources