> For the complete documentation index, see [llms.txt](https://docs.release.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.release.com/integrations/integrations-overview/launchdarkly-integration.md).

# LaunchDarkly integration

The functionality of Release's LaunchDarkly integration and how to set it up

Release's LaunchDarkly integration allows you to have a pristine, isolated LaunchDarkly environment to use for testing.

Sharing feature flags between multiple environments can cause testing and reliability issues. Release solves this problem by creating a new LaunchDarkly environment each time you deploy a new Release environment and storing the SDK key, mobile key, and client key as environment variables your application can access.

Release handles creating and deleting LaunchDarkly environments with little configuration needed.

## Set up the integration

Navigate to the **Integrations** tab for your account.

![](https://585411240-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1neGLLQ0sDXeK6ooSo%2Fuploads%2Fgit-blob-387ff74bce31e102d91a4233fc5cb7f147d4e139%2Fsettings-integrations.png?alt=media\&token=7c52ddc2-32a4-4360-8d79-30386a68496a)

Each field in the set-up form is required. Except for the **Access Token** field, you can use the defaults provided.

* **Project Key**: This is the key for the project you want your environments created under. The default value is `default`, as LaunchDarkly always has a project with the key `default`.
* **Access Token**: This is the token for the account you would like to create environments under in LaunchDarkly. You can create or find the access token under **Account Settings** -> **Authorization**. All access tokens start with `api-`.
* **Environment Variables**: The remaining fields define the names of the environment variables Release will use to store the various API keys from LaunchDarkly. You can change these names to anything you like. Keys are stored as encrypted K8s secrets.

You will need the LaunchDarkly access token to set up your SDK client so that you can choose variations of flags in your application.

![](https://585411240-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1neGLLQ0sDXeK6ooSo%2Fuploads%2Fgit-blob-e3c99b033731d7d85101669b028026ad41e94a69%2Fimage.png?alt=media)

Once you have saved these configurations, Release will attempt to use your **access token** to connect to your LaunchDarkly account. If that works, the integration is ready to go! If not, you'll see errors and can correct any mistakes you have made.

## Using the LaunchDarkly integration

The integration consists of two parts, both of which are automated and handled by Release.

* **Pre-deployment step:** The LaunchDarkly integration will add a task to each of your deployments to create the feature flag environment.
* **Pre-delete step:** When you delete an environment, a step will be injected that cleans up by deleting the environment in LaunchDarkly.

![](https://585411240-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1neGLLQ0sDXeK6ooSo%2Fuploads%2Fgit-blob-bea6231d5368c3cda147f1ffefd98280d9c2cc50%2FLD%20Workflow.png?alt=media)

### Pre-deployment step

The pre-deployment step will create an environment in LaunchDarkly the first time you deploy a space or new configuration.

![](https://585411240-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1neGLLQ0sDXeK6ooSo%2Fuploads%2Fgit-blob-166e01c87a6054a377bde11f1e4313840e79c138%2Fsetup-deployment-with-launchdarkly.png?alt=media)

The environment variables you specified during set up will be populated and exposed to your containers via K8s secrets.

![](https://585411240-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1neGLLQ0sDXeK6ooSo%2Fuploads%2Fgit-blob-ee9d7c86d73a0d619af7d0a207a185d112073500%2Fimage.png?alt=media)

You can then use these environment variables in your code to access your feature flags as you normally would.

### Pre-delete step

The pre-delete step is invoked when a Release environment is removed, whether manually through the UI or when a pull request is merged or closed. The LaunchDarkly integration will remove the corresponding LaunchDarkly environment automatically when the Release environment is removed.

## Examples

Below are some examples of how to consume the environment variables to use the LaunchDarkly integration.

### Rails: Setting up LaunchDarkly SDK client

In this example, we will configure the LaunchDarkly SDK client with the specific API key for your environment. This example is based on the [Ruby SDK reference](https://github.com/releasehub-com/docs/tree/210ccabc0ef3e5ace15fed68e4e48f971fbc662b/sdk/server-side/ruby/README.md).

{% hint style="info" %}
When running locally, you can use the dotenv gem (<https://github.com/bkeepers/dotenv>) to set your LaunchDarkly environment variables to test values.
{% endhint %}

* Install the [Ruby SDK gem](https://github.com/launchdarkly/ruby-server-sdk).
* Create a file in `config/initializers/launchdarkly_client.rb`.
* Copy the code below into `config/initializers/launchdarkly_client.rb`.

```ruby
=begin

  #Uncomment this section if you would like to use the LaunchDarklyApi gem (https://github.com/launchdarkly/api-client-ruby).
  #This is NOT the gem for using the Ruby LaunchDarkly SDK (https://github.com/launchdarkly/ruby-server-sdk).
  #Most people do not need to use the LaunchDarkly Rest API defined here: https://apidocs.launchdarkly.com/reference, but
  #instead just want to use the SDK to interact with the feature flags in their specific environment.
  #If you would like to use the LaunchDarkly Rest API, make sure to install the gem besides uncommenting these lines.

access_token = ENV['LAUNCHDARKLY_ACCESS_TOKEN']

LaunchDarklyApi.configure do |config|
  config.api_key['Authorization'] = access_token
  config.debugging = true
end

=end

##To use the LaunchDarkly Ruby SDK, you will need the specific SDK key.
##In this example, I'm setting up `LDClient` under the `Rails.configuration` so it's accessible anywhere
##in your Rails project.
Rails.configuration.ld_client =
  LaunchDarkly::LDClient.new(ENV['LAUNCHDARKLY_ENV_SPECIFIC_SDK_KEY'])
```

**Example of using the `LDClient` you defined above in your Rails application**

```ruby
test_flag = Rails.configuration.ld_client.variation("test-flag", {key: "user@test.com"}, false)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.release.com/integrations/integrations-overview/launchdarkly-integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
