Skip to main content

Documentation Index

Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

Server-side SDKs

Here are the configuration options for private context and user attributes in server-side SDKs:

.NET (server-side)

In the server-side .NET SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • When creating the LaunchDarkly Configuration object, you can configure Events with AllAttributesPrivate, which takes in a boolean parameter. If true, the SDK removes all attributes for all contexts before sending the context to LaunchDarkly, except the key.
  • Or, you can configure Events with PrivateAttributes, which takes any number of attribute names or slash-delimited paths to designated a JSON property within an attribute, such as /address/street. If any context has a custom or built-in attribute that matches one of these names, the SDK removes it before sending the context to LaunchDarkly.
For example:
      // All attributes marked as private
      var config = Configuration.Builder("YOUR_SDK_KEY")
          .Events(
              Components.SendEvents()
                 .AllAttributesPrivate(true)  // defaults to false
          )
          .Build();

      var client = new LDClient(config);

      // Two attributes marked as private
      var config = Configuration.Builder("YOUR_SDK_KEY")
          .Events(
              Components.SendEvents()
                .PrivateAttributes("email", "address")
          )
          .Build();

      var client = new LDClient(config);
You can also mark attributes as private when building the context object by calling Private() after setting the attribute on the context builder.For example:
      var context = Context.Builder("example-context-key")
          .Set("email", "sandy@example.com")
          .Private("email")
          .Build();
When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Apex

You can configure the Apex SDK to treat some or all user attributes as private user attributes, either using the LDConfig object or on a per-user basis.When creating the LDConfig object, you can use setAllAttributesPrivate(true). When you do this, all user attributes, except the key, are redacted before the SDK sends the user to LaunchDarkly.Here’s how:
      LDConfig config = new LDConfig.Builder()
          .setAllAttributesPrivate(true)
          .build();
You can also define private attribute names on a per-user basis:
      Set<String> privateAttributes = new Set<String>();
      privateAttributes.add('firstName');

      LDUser user = new LDUser.Builder('example-user-key')
          .setFirstName('alice')
          .setPrivateAttributeNames(privateAttributes)
          .build();

C++ (server-side)

In the C++ SDK there are three ways to define private attributes for the LaunchDarkly client:
  • When creating the config object, you can use AllAttributesPrivate. When you do this, the SDK only sends the context key and kind to LaunchDarkly. For example:
        auto config_builder = server_side::ConfigBuilder("YOUR_SDK_KEY");
        config_builder.Events().AllAttributesPrivate(true);
        auto config = config_builder.Build();
  • When creating the config object, you can list specific private attributes with PrivateAttributes. The SDK removes all attributes in this list before sending the context to LaunchDarkly. Here’s how:
        auto config_builder = server_side::ConfigBuilder("YOUR_SDK_KEY");
        config_builder.Events().PrivateAttributes({"email"});
        auto config = config_builder.Build();
        if (!config) {
            /* an error occurred, config is not valid */
        }
  • You can also define private attributes on a per-context basis. For example:
        auto context = ContextBuilder()
          .Kind("user", "example-user-key")
          .SetPrivate("email", "sandy@example.com")
          .Build();
To learn more, read ContextBuilder.

Erlang

Here’s how to set context attributes as private for all or just some contexts:
      %% All attributes marked as private
      ldclient:start_instance("YOUR_SDK_KEY", #{private_attributes => all}).

      %% Two attributes marked as private
      ldclient:start_instance("YOUR_SDK_KEY", #{private_attributes => [<<"email">>, <<"address">>]}).
Here’s how to set context attributes as private for a specific context:
          ContextWithPrivateAttributes = ldclient_context:set_private_attributes([<<"name">>, <<"/address/street">>],
              ldclient_context:set(<<"name">>, <<"Global Health Services">>,
              ldclient_context:set(<<"email">>, <<"info@globalhealthexample.com">>,
              ldclient_context:set(<<"address">>, #{
                  <<"street">> => <<"123 Main Street">>,
                  <<"city">> => <<"Springfield">>
              },
          ldclient_context:new(<<"context-key-456def">>, <<"organization">>))))),
In the example, only the name and /address/street attributes are private for this context.

Go

In the Go SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • You can set the configuration option AllAttributesPrivate to true. If you enable this, the SDK removes all attributes for all contexts before it sends the context to LaunchDarkly, except the key and kind.
  • You can set the configuration option PrivateAttributes to a list of attribute names. If any context has an attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
Here’s how to to define private attributes:
      import (
          ld "github.com/launchdarkly/go-server-sdk/v6"
          "github.com/launchdarkly/go-server-sdk/v6/ldcomponents"
      )

      var config ld.Config

      // Make all attributes private for all contexts
      config.Events = ldcomponents.SendEvents().AllAttributesPrivate(true)

      // Or, make just the email and address attributes private for all contexts
      config.Events = ldcomponents.SendEvents().
          PrivateAttributes("name", "email")
You can also define a set of private attributes on the context object itself. In the following example, “email” and the “street” field of the “address” attribute are private for this context, in addition to any private attributes that were specified globally:
      import (
          "github.com/launchdarkly/go-sdk-common/v3/ldcontext"
      )

      context := ldcontext.NewBuilder("example-context-key").
          Kind("organization").
          Name("Global Health Services").
          SetString("email", "info@globalhealthexample.com").
          SetValue("address", ldvalue.ObjectBuild().
              SetString("street", "123 Main Street").
              SetString("city", "Springfield")).
          Private("email").
          Private("/address/street").
          Build()

Haskell

Optionally, you can configure the Haskell SDK to treat some or all context attributes as private attributes. You can use private context attributes for targeting purposes, but the SDK removes private context attributes from the data it sends to LaunchDarkly.There are two ways to define private attributes for the entire LaunchDarkly client:
  • When you create the Config object, use configSetAllAttributesPrivate to set all context attributes as private. When you do this, all context attributes, except the key and kind, are removed before the SDK sends the context to LaunchDarkly.
  • When you create the Config object, you can list specific private attributes with configSetPrivateAttributeNames. If any context has attributes named in this list, the SDK removes them before sending the context to LaunchDarkly.
Here’s how:
      -- All attributes marked private
      makeConfig "YOUR_SDK_KEY" & configSetAllAttributesPrivate True

      -- Two attributes marked private
      import qualified Data.Set as S
      import qualified LaunchDarkly.Server.Reference as R

      makeConfig sdkKey
        & configSetAllAttributesPrivate True
        & configSetPrivateAttributeNames (S.fromList $ map R.makeLiteral ["name", "email"])
      config = LaunchDarkly::Config.new({private_attributes: ["name", "email"]})
You can also define private attribute names on a per-context basis.For example:
      makeContext "key" "user"
        & withName "Sandy"
        & withAttribute "email" "sandy@example.com"
        & withPrivateAttributes (S.fromList $ map R.makeLiteral ["name", "email"])

Java

In the Java SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • When creating the LDConfig object, you can call the allAttributesPrivate method, which takes in a boolean parameter. If true, all context attributes except the key for all contexts are removed before the SDK sends the context to LaunchDarkly.
  • When creating the LDConfig object, you can call the privateAttributes method, which takes in a set of custom or built-in attributes as a parameter. If any context has a custom or built-in attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
Here’s how to define private attributes:
      // All attributes marked private
      LDConfig configWithAllAttributesPrivate = new LDConfig.Builder()
        .events(
          Components.sendEvents()
            .allAttributesPrivate(true)
        )
        .build();

      // Some attributes marked private
      LDConfig configWithSpecificAttributesPrivate = new LDConfig.Builder()
        .events(
          Components.sendEvents()
            .privateAttributes("name", "email", "someAttribute")
        )
        .build();
You can also mark attributes as private when building the context object by calling the privateAttributes builder method. For example:
      LDContext context = LDContext.builder("example-context-key")
        .set("email", "sandy@example.com")
        .privateAttributes("email")
        .build();
When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Lua

In the Lua SDK there are two ways to define private attributes for the LaunchDarkly client:
  • Use allAttributesPrivate to remove all context attributes except for the kind and key from all contexts before the SDK sends the contexts to LaunchDarkly.
  • Use privateAttributes to designate a list of private attributes. If any context has an attribute named in this list, the SDK removes that attribute before sending the context to LaunchDarkly.
Here’s how to mark attributes as private:
      -- sets all attributes private
      local configAllPrivate = {
          events = {
              allAttributesPrivate = true
          }
      }

      -- sets "email" and "address" private
      local configSomePrivate = {
          events = {
              privateAttributes = { "email", "address" }
          }
      }
You can also define private attributes for a particular context using a list of privateAttributes:
      local user = ld.makeContext({
          user = {
              key  = "example-user-key",
              attributes = {
                  firstName = "Sandy",
                  lastName  = "Smith",
                  email     = "sandy@example.com",
                  groups    = { "Acme", "Global Health Services" }
              },
              privateAttributes = { "email "}
          }
      })
To learn more, read clientInit and makeContext.

Node.js (server-side)

In the Node.js SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • In the LaunchDarkly LDOptions, you can set allAttributesPrivate to true. If you enable this, the SDK removes all attributes for all contexts before sending the context to LaunchDarkly, except the kind and key.
  • In the LaunchDarkly LDOptions object, you can define a list of privateAttributes. If any context has a custom or built-in attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
For example:
      // All attributes marked private
      const options = {
        allAttributesPrivate: true
      };
      client = ld.init('YOUR_SDK_KEY', options);

      // Two attributes marked private
      const options = {
        privateAttributes: ['email', 'address']
      };
      client = ld.init('YOUR_SDK_KEY', options);
You can also define a set of privateAttributes on the context object. For example:
      import * as ld from '@launchdarkly/node-server-sdk';

      const user: ld.LDContext = {
        kind: 'user',
        key: 'example-user-key',
        email: 'sandy@example.com',
        privateAttributes: ['email'],
      };
When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

PHP

In the PHP SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • In the LaunchDarkly config, you can set all_attributes_private to true. If you enable this, the SDK removes all attributes except the key and kind from a context before sending the context to LaunchDarkly.
  • In the LaunchDarkly config object, you can define a list of private_attribute_names. If any context has a custom or built-in attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
For example:
      // All attributes marked private
      $client = new LaunchDarkly\LDClient($sdkKey, ['all_attributes_private' => true]);

      // Two attributes marked private
      $client = new LaunchDarkly\LDClient($sdkKey, ['private_attribute_names' => ['name', 'email']]);
You can also mark attributes as private when building the context object by calling the equivalent “private” LDContextBuilder method.For example:
      $context = LDContext::builder('example-context-key')
          ->set('email', 'sandy@example.com')
          ->private('email')
          ->build();
When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Python

In the Python SDK there are two ways to define private attributes for the LaunchDarkly client:
  • In the LaunchDarkly config, you can set all_attributes_private to true. If you enable this, the SDK removes all context attributes for all contexts before sending the context to LaunchDarkly, except the key.
  • In the LaunchDarkly config object, you can define a list of attributes in private_attributes. If any context has a custom or built-in attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
For example:
      # All attributes marked private
      config = Config(all_attributes_private=True)

      # Two attributes marked private
      config = Config(private_attributes=["name", "email"])
You can also mark attributes as private when building the context object by calling the private builder method. For example:
      context = Context.builder("example-context-key") \
          .set("email", "sandy@example.com") \
          .private("email") \
          .build()
When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Ruby

In the Ruby SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • In the LaunchDarkly config, you can set all_attributes_private to true. If you enable this, the SDK removes all context attributes for all contexts before sending the context to LaunchDarkly, except the key.
  • In the LaunchDarkly config object, you can define a list of private_attributes. If any context has a custom or built-in attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
For example:
      # All attributes marked private
      config = LaunchDarkly::Config.new({all_attributes_private: true})

      # Two attributes marked private
      config = LaunchDarkly::Config.new({private_attributes: ["name", "email"]})
You can also define a set of privateAttributes on the context object. For example:
      context = LaunchDarkly::LDContext.create({
        key: "example-user-key",
        kind: "user",
        firstName: "Sandy",
        lastName: "Smith",
        email: "sandy@example.com",
        groups: ["Acme", "Global Health Services"],
        _meta: {
          privateAttributes: ['email']
        }
      })
When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Rust

In the Rust SDK there are two ways to define private attributes for the entire LaunchDarkly client:
  • In the LaunchDarkly config object, you can set all_attributes_private to true. If you enable this, the SDK removes all attributes for all contexts before sending the context to LaunchDarkly, except the key and kind.
  • In the LaunchDarkly config object, you can define a list of private_attributes. If any contexts has an attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
For example:
      // All attributes marked private
      let config_builder = ConfigBuilder::new("YOUR_SDK_KEY");
      let mut processor_builder = EventProcessorBuilder::new();
      processor_builder.all_attributes_private(true);
      config_builder.event_processor(&processor_builder);

      // Two attributes marked private
      let config_builder = ConfigBuilder::new("YOUR_SDK_KEY");
      let mut processor_builder = EventProcessorBuilder::new();
      processor_builder.private_attributes(
          vec!["email".into(), "address".into()]
              .into_iter()
              .collect(),
      );
      config_builder.event_processor(&processor_builder);
You can also define private attributes on the context object. For example:
      let context = ContextBuilder::new("example-context-key")
          .set_value("email", "youremail@example.com".into())
          .add_private_attribute(Reference::new("email"))
          .build()?;
When the SDK sends this context back to LaunchDarkly, it removes the email attribute.