Private attributes

Overview

This topic explains how to configure private context and user attributes in LaunchDarkly SDKs. These features are available for client-side, server-side, and AI SDKs.

You can optionally configure your SDK to treat some or all attributes as private context attributes. You can use private context attributes for targeting purposes, but the SDK removes them from the context data it sends back to LaunchDarkly.

The SDK always sends the context key and kind

The context key is not optional. You cannot set either the context key or the context kind as a private attribute.

If you initially mark an attribute as private, LaunchDarkly will continue to treat the attribute as private in subsequent evaluations as long as the context is in the Contexts list, even if you later remove the “private” designation from the attribute. If you no longer want LaunchDarkly to treat the attribute as private, remove the “private” designation within the SDK, delete the context from the Contexts list, and re-evaluate the context.

After you configure private attributes within your SDK, the context details page in the LaunchDarkly user interface shows the private attributes under a _meta section. The values of these attributes are not displayed:

The "Attributes" section of the context details page, showing private attributes in a "_meta" section.

The "Attributes" section of the context details page, showing private attributes in a "_meta" section.

Depending on the type of SDK you use, LaunchDarkly does not receive or store the information in private attributes:

  • If you are using a server-side or AI SDK, the SDK will not send the private attribute back to LaunchDarkly.
  • If you are using a client-side SDK, the SDK will send the private attribute back to LaunchDarkly for evaluation. However, the SDK won’t send the attribute to LaunchDarkly in events data, LaunchDarkly won’t store the private attribute, and the private attribute will not appear on the Contexts list or on the detail page for the context.
Newer versions of LaunchDarkly SDKs replace users with contexts

A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: “users.” To learn more, read Contexts.

Creating contexts and evaluating flags based on them is supported in the latest major versions of most of our SDKs. For these SDKs, the code samples on this page include the two most recent versions.

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

Client-side SDKs

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

.NET (client-side)

In the client-side .NET SDK there are two ways to define private attributes for the entire LaunchDarkly client:

  • When creating the LaunchDarkly Configuration object, you can call the AllAttributesPrivate method, which takes in a boolean parameter. If true, all context attributes except the kind and key are removed for all contexts before the SDK sends the context to LaunchDarkly.
  • When creating the LaunchDarkly Configuration object, you can call the PrivateAttributes method, which takes any number of attribute names or slash-delimited paths to designated JSON properties 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:

1// All attributes marked private
2var configAllPrivate = Configuration
3 .Builder("mobile-key-123abc", ConfigurationBuilder.AutoEnvAttributes.Enabled)
4 .AllAttributesPrivate(true)
5 .Build();
6LdClient client = LdClient.Init(configAllPrivate, context);
7
8// Two attributes marked private
9var configSomePrivate = Configuration.Builder("mobile-key-123abc")
10 .PrivateAttributes("email", "address")
11 .Build();
12LdClient client = LdClient.Init(configSomePrivate, context);

You can also mark attributes as private when building the context object by calling Private() on the context builder.

For example:

1var context = Context.Builder("context-key-123abc")
2 .Set("email", "sandy@example.com")
3 .Private("email")
4 .Build();

When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Android

In the Android SDK you can define private attributes for the entire LaunchDarkly client. When creating the LDConfig object, 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 set, the SDK removes it before sending the context to LaunchDarkly.

Here’s how to configure private attributes:

1// All attributes marked private
2LDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled)
3 .mobileKey("mobile-key-123abc")
4 .events(
5 Components.sendEvents()
6 .allAttributesPrivate(true)
7 )
8 .build();
9
10// Two attributes marked private
11LDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled)
12 .mobileKey("mobile-key-123abc")
13 .events(
14 Components.sendEvents()
15 .privateAttributes("name", "group")
16 )
17 .build();

You can also mark attributes as private when building the context object by using the private versions of the builder methods to set the attributes. For example:

1LDContext context = LDContext.builder("context-key-123abc")
2 .set("email", "sandy@example.com")
3 .set("name", "Sandy")
4 .set("group", "Microsoft")
5 .privateAttributes("name", "group")

When the SDK sends this context back to LaunchDarkly, it removes the name and group attributes.

C++ (client-side)

In the C++ SDK there are two ways to define private attributes for the LaunchDarkly client:

  • When using the ConfigBuilder, you can call AllAttributesPrivate(). When you do this, all context attributes except the kind and key are removed before the SDK sends the context to LaunchDarkly.
  • When using the ConfigBuilder, you can configure a set of PrivateAttributes(). If any context has an attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.

Here’s how:

1/* sets all attributes private */
2auto config_builder = client_side::ConfigBuilder("mobile-key-123abc");
3config_builder.Events().AllAttributesPrivate(true);
4auto config_all_private = config_builder.Build();
5
6/* sets "email" and "address" private */
7auto config_builder = client_side::ConfigBuilder("mobile-key-123abc");
8config_builder.Events().PrivateAttributes({"email", "address"});
9auto configSomePrivate = config_builder.Build();

You can also define private attributes for a particular context by calling .SetPrivate() in the ContextBuilder.

Here’s how:

C++ SDK v3.0
1auto context = ContextBuilder()
2 .Kind("user", "user-key-123abc")
3 .Name("Sandy Smith")
4 .SetPrivate("email", "sandy@example.com")
5 .Build();

To learn more, read ContextBuilder.

Electron

To mark all user attributes except the key as private, use the allAttributesPrivate option:

1const user = {
2 key: 'user-key-123abc',
3 name: 'Sandy Smith',
4 email: 'sandy@example.com'
5};
6
7const client = LDElectron.initialize('client-side-id-123abc', user, {
8 allAttributesPrivate: true
9});

In the above example, the SDK removes the name and email attributes.

You can also specify an array of which attributes should be private with the privateAttributeNames option. You can configure this option on a per-user basis by specifying which attributes should be private in your user object.

This option is configured in both the user object and the configuration object:

1const user = {
2 key: 'user-key-123abc',
3 name: 'Sandy Smith',
4 email: 'sandy@example.com',
5 privateAttributeNames: ['email']
6};
7
8const client = LDElectron.initialize('client-side-id-123abc', user, {
9 privateAttributeNames: ['email']
10});

In the above example, the SDK sends only the key and name back to LaunchDarkly.

Flutter

In the Flutter SDK, you can define private attributes for the entire LaunchDarkly client. When you create the LDConfig object, you can set all attributes private for all contexts. You can also provide a list of attributes to the globalPrivateAttributes option. If any context has an attribute named in this set, the SDK removes it before sending the context to LaunchDarkly.

1final config = LDConfig(
2 CredentialSource.fromEnvironment,
3 AutoEnvAttributes.enabled,
4 allAttributesPrivate: true, // all attributes marked private
5 globalPrivateAttributes: ['user/email', 'user/group'], // two attributes marked private for the 'user' context kind
6)

You can also mark attributes as private when building the context object by using the private optional parameter. For example:

1final context = LDContextBuilder()
2 .kind('user', 'user-key-123abc'),
3 .setString('name', 'Sandy')
4 .setString('email', 'sandy@example.com', private: true)
5 .setString('group', 'microsoft', private: true)
6 .build();

When the SDK sends this context back to LaunchDarkly, the email and group attributes are removed.

To learn more about the configuration options for private attributes, read allAttributesPrivate and globalPrivateAttributes. To learn more about setting private attributes for a specific context, read LDContext.

iOS

In the iOS SDK there are two ways to define private attributes for the entire LaunchDarkly client:

  • When creating the LDConfig object, you can set the allContextAttributesPrivate attribute to true.
  • When creating the LDConfig object, you can set the privateContextAttributes property to a list of References, such as [Reference("name"), Reference("/address/state")]. 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:

1// All attributes marked private
2config = LDConfig(mobileKey: "mobile-key-123abc", autoEnvAttributes: .enabled)
3config.allContextAttributesPrivate = true
4
5// Two attributes marked private
6config = LDConfig(mobileKey: "mobile-key-123abc", autoEnvAttributes: .enabled)
7config.privateContextAttributes = [Reference("email"), Reference("address")]

You can also mark attributes as private on a particular LDContext instance, for example:

1var contextBuilder = LDContextBuilder(key: "context-key-123abc")
2contextBuilder.trySetValue("name", .string("Sandy"))
3contextBuilder.trySetValue("group", .array([LDValue(stringLiteral: "microsoft")]))
4contextBuilder.addPrivateAttribute(Reference("name"))
5contextBuilder.addPrivateAttribute(Reference("group"))
6
7let context = try contextBuilder.build().get()

JavaScript

You can configure the private attributes option either in the configuration object or in the context object.

In the configuration object, to mark all attributes except the key as private in the JavaScript SDK, use the allAttributesPrivate option. To mark some attributes as private specify your array of attributes in the privateAttributes configuration option.

Here’s how:

1const context = {
2 kind: 'user',
3 key: 'user-key-123abc',
4 name: 'Sandy Smith',
5 email: 'sandy@example.com'
6};
7
8// All attributes marked private
9const ldclient = ld.initialize('client-side-id-123abc', context, options = {
10 allAttributesPrivate: true
11});
12// Two attributes marked private
13const ldclient = ld.initialize('client-side-id-123abc', context, options = {
14 privateAttributes: ['email', 'name']
15});

In the context object, specify your array of attributes in the privateNames field of the reserved _meta property.

Here’s how:

1const context = {
2 kind: 'user',
3 key: 'context-key-123abc',
4 name: 'Sandy Smith',
5 email: 'sandy@example.com',
6 _meta: {
7 privateAttributes: ['email']
8 }
9};
10
11const ldclient = ld.initialize('client-side-id-123abc', context, options = {
12 privateAttributes: ['email']
13});

In the above example, the SDK sends only the context’s key and name back to LaunchDarkly.

Node.js (client-side)

To mark all user attributes except the key as private in the Node.js SDK, you can use the allAttributesPrivate option:

1const context = {
2 kind: 'user',
3 key: 'user-key-123abc',
4 name: 'Sandy Smith',
5 email: 'sandy@example.com'
6};
7// All attributes marked private
8const client = ld.initialize('client-side-id-123abc', context, {
9 allAttributesPrivate: true
10});
11// Two attributes marked private
12const client = ld.initialize('client-side-id-123abc', context, {
13 privateAttributes: ['email', 'name']
14});

You can also specify an array of which attributes should be private with the privateAttributes option. You can configure this option on a per-context basis by specifying which attributes should be private in your context object.

You can configure this option in both the context object and the configuration object:

1const context = {
2 kind: 'user',
3 key: 'user-key-123abc',
4 name: 'Sandy Smith',
5 email: 'sandy@example.com'
6 _meta: {
7 privateAttributes: ['email']
8 }
9};
10
11const client = ld.initialize('client-side-id-123abc', context, {
12 privateAttributes: ['email']
13});

In the above example, the SDK sends only the context key and name back to LaunchDarkly.

React Native

You can configure this option in the configuration object, to apply to all contexts, either for all attributes or some attributes:

1// All attributes marked private
2const options = {
3 allAttributesPrivate: true
4}
5const client = new ReactNativeLDClient('mobile-key-123abc', AutoEnvAttributes.Enabled, options);
6
7// Two attributes marked private
8const options = {
9 privateAttributes: ['email', 'address']
10}
11const client = new ReactNativeLDClient('mobile-key-123abc', AutoEnvAttributes.Enabled, options);

To learn more, read allAttributesPrivate and privateAttributes.

You can also mark an attribute as private for a particular context:

React Native SDK v7+
1const context = {
2 kind: 'user',
3 key: 'user-key-123abc',
4 firstName: 'Sandy',
5 lastName: 'Smith',
6 email: 'sandy@example.com',
7 address: {
8 street: '123 Main St',
9 city: 'Springfield'
10 },
11 _meta: {
12 privateAttributes: ['email', '/address/street']
13 }
14};

For attributes that are objects, you can mark specific fields private, using the / delimiter followed by the attribute name, then the / delimiter followed by the JSON property within the value. In the example, the attribute "address": { "street": "Main St", "city": "Springfield" } has only the /address/street marked as private.

React Web

All context-related functionality provided by the JavaScript SDK is also available in the React Web SDK.

Roku

You can configure this option in the configuration object, to apply to all contexts, either for all attributes or some attributes:

Brightscript
1' All attributes marked private
2config = LaunchDarklyConfig("mobile-key-123abc", launchDarklyTaskNode)
3config.setAllAttributesPrivate(true)
4
5LaunchDarklySGInit(config, context)
6client = LaunchDarklySG(launchDarklyTaskNode)
7
8' Two attributes marked private
9config = LaunchDarklyConfig("mobile-key-123abc", launchDarklyTaskNode)
10config.addPrivateAttribute("email")
11config.addPrivateAttribute("address")
12
13LaunchDarklySGInit(config, context)
14client = LaunchDarklySG(launchDarklyTaskNode)

You can also mark an attribute as private for a particular context:

BrightScript
1' when creating a context
2context = LaunchDarklyCreateContext({
3 "kind": "user",
4 "key": "context-key-123-abc",
5 "email": "sandy@example.com",
6 "_meta": { privateAttributes: ["email"] }
7})
8
9' for an existing context
10context.addPrivateAttribute("email")
11context.addPrivateAttribute("/address/street")

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:

.NET SDK v7.0 (C#)
1// All attributes marked as private
2var config = Configuration.Builder("sdk-key-123abc")
3 .Events(
4 Components.SendEvents()
5 .AllAttributesPrivate(true) // defaults to false
6 )
7 .Build();
8
9var client = new LDClient(config);
10
11// Two attributes marked as private
12var config = Configuration.Builder("sdk-key-123abc")
13 .Events(
14 Components.SendEvents()
15 .PrivateAttributes("email", "address")
16 )
17 .Build();
18
19var 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:

1var context = Context.Builder("context-key-123abc")
2 .Set("email", "sandy@example.com")
3 .Private("email")
4 .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:

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

You can also define private attribute names on a per-user basis:

Java
1Set<String> privateAttributes = new Set<String>();
2privateAttributes.add('firstName');
3
4LDUser user = new LDUser.Builder('user-key-123abc')
5 .setFirstName('alice')
6 .setPrivateAttributeNames(privateAttributes)
7 .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:

    1auto config_builder = server_side::ConfigBuilder("sdk-key-123abc");
    2config_builder.Events().AllAttributesPrivate(true);
    3auto 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:

    1auto config_builder = server_side::ConfigBuilder("sdk-key-123abc");
    2config_builder.Events().PrivateAttributes({"email"});
    3auto config = config_builder.Build();
    4if (!config) {
    5 /* an error occurred, config is not valid */
    6}
  • You can also define private attributes on a per-context basis. For example:

    1auto context = ContextBuilder()
    2 .Kind("user", "user-key-123abc")
    3 .SetPrivate("email", "sandy@example.com")
    4 .Build();

To learn more, read ContextBuilder.

Erlang

Here’s how to set context attributes as private for all or just some contexts:

Erlang
1%% All attributes marked as private
2ldclient:start_instance("sdk-key-123abc", #{private_attributes => all}).
3
4%% Two attributes marked as private
5ldclient:start_instance("sdk-key-123abc", #{private_attributes => [<<"email">>, <<"address">>]}).

Here’s how to set context attributes as private for a specific context:

Erlang
1 ContextWithPrivateAttributes = ldclient_context:set_private_attributes([<<"name">>, <<"/address/street">>],
2 ldclient_context:set(<<"name">>, <<"Global Health Services">>,
3 ldclient_context:set(<<"email">>, <<"info@globalhealthexample.com">>,
4 ldclient_context:set(<<"address">>, #{
5 <<"street">> => <<"123 Main Street">>,
6 <<"city">> => <<"Springfield">>
7 },
8 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:

1import (
2 ld "github.com/launchdarkly/go-server-sdk/v6"
3 "github.com/launchdarkly/go-server-sdk/v6/ldcomponents"
4)
5
6var config ld.Config
7
8// Make all attributes private for all contexts
9config.Events = ldcomponents.SendEvents().AllAttributesPrivate(true)
10
11// Or, make just the email and address attributes private for all contexts
12config.Events = ldcomponents.SendEvents().
13 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:

Go SDK v6.0
1import (
2 "github.com/launchdarkly/go-sdk-common/v3/ldcontext"
3)
4
5context := ldcontext.NewBuilder("context-key-123abc").
6 Kind("organization").
7 Name("Global Health Services").
8 SetString("email", "info@globalhealthexample.com").
9 SetValue("address", ldvalue.ObjectBuild().
10 SetString("street", "123 Main Street").
11 SetString("city", "Springfield")).
12 Private("email").
13 Private("/address/street").
14 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:

Haskell SDK v4.0
1-- All attributes marked private
2makeConfig "sdk-key-123abc" & configSetAllAttributesPrivate True
3
4-- Two attributes marked private
5import qualified Data.Set as S
6import qualified LaunchDarkly.Server.Reference as R
7
8makeConfig sdkKey
9 & configSetAllAttributesPrivate True
10 & configSetPrivateAttributeNames (S.fromList $ map R.makeLiteral ["name", "email"])
11config = LaunchDarkly::Config.new({private_attributes: ["name", "email"]})

You can also define private attribute names on a per-context basis.

For example:

1makeContext "key" "user"
2 & withName "Sandy"
3 & withAttribute "email" "sandy@example.com"
4 & 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:

1// All attributes marked private
2LDConfig configWithAllAttributesPrivate = new LDConfig.Builder()
3 .events(
4 Components.sendEvents()
5 .allAttributesPrivate(true)
6 )
7 .build();
8
9// Some attributes marked private
10LDConfig configWithSpecificAttributesPrivate = new LDConfig.Builder()
11 .events(
12 Components.sendEvents()
13 .privateAttributes("name", "email", "someAttribute")
14 )
15 .build();

You can also mark attributes as private when building the context object by calling the privateAttributes builder method. For example:

1LDContext context = LDContext.builder("context-key-123abc")
2 .set("email", "sandy@example.com")
3 .privateAttributes("email")
4 .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:

1-- sets all attributes private
2local configAllPrivate = {
3 events = {
4 allAttributesPrivate = true
5 }
6}
7
8-- sets "email" and "address" private
9local configSomePrivate = {
10 events = {
11 privateAttributes = { "email", "address" }
12 }
13}

You can also define private attributes for a particular context using a list of privateAttributes:

1local user = ld.makeContext({
2 user = {
3 key = "user-key-123abc",
4 attributes = {
5 firstName = "Sandy",
6 lastName = "Smith",
7 email = "sandy@example.com",
8 groups = { "Google", "Microsoft" }
9 },
10 privateAttributes = { "email "}
11 }
12})

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:

1// All attributes marked private
2const options = {
3 allAttributesPrivate: true
4};
5client = ld.init('sdk-key-123abc', options);
6
7// Two attributes marked private
8const options = {
9 privateAttributes: ['email', 'address']
10};
11client = ld.init('sdk-key-123abc', options);

You can also define a set of privateAttributes on the context object. For example:

1import * as ld from '@launchdarkly/node-server-sdk';
2
3const user: ld.LDContext = {
4 kind: 'user',
5 key: 'user-key-123abc',
6 email: 'sandy@example.com',
7 privateAttributes: ['email'],
8};

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:

PHP SDK v5.0
1// All attributes marked private
2$client = new LaunchDarkly\LDClient($sdkKey, ['all_attributes_private' => true]);
3
4// Two attributes marked private
5$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:

1$context = LDContext::builder('context-key-123abc')
2 ->set('email', 'sandy@example.com')
3 ->private('email')
4 ->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:

Python SDK v8.0
1# All attributes marked private
2config = Config(all_attributes_private=True)
3
4# Two attributes marked private
5config = 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:

1context = Context.builder("context-key-123abc") \
2 .set("email", "sandy@example.com") \
3 .private("email") \
4 .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:

Ruby SDK v7.0
1# All attributes marked private
2config = LaunchDarkly::Config.new({all_attributes_private: true})
3
4# Two attributes marked private
5config = LaunchDarkly::Config.new({private_attributes: ["name", "email"]})

You can also define a set of privateAttributes on the context object. For example:

1context = LaunchDarkly::LDContext.create({
2 key: "user-key-123abc",
3 kind: "user",
4 firstName: "Sandy",
5 lastName: "Smith",
6 email: "sandy@example.com",
7 groups: ["Google", "Microsoft"],
8 _meta: {
9 privateAttributes: ['email']
10 }
11})

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:

Rust SDK v1
1// All attributes marked private
2let config_builder = ConfigBuilder::new("sdk-key-123abc");
3let mut processor_builder = EventProcessorBuilder::new();
4processor_builder.all_attributes_private(true);
5);
6config_builder.event_processor(&processor_builder);
7
8// Two attributes marked private
9let config_builder = ConfigBuilder::new("sdk-key-123abc");
10let mut processor_builder = EventProcessorBuilder::new();
11processor_builder.private_attributes(
12 vec!["email".into(), "address".into()]
13 .into_iter()
14 .collect(),
15);
16config_builder.event_processor(&processor_builder);

You can also define private attributes on the context object. For example:

1let context = ContextBuilder::new("context-key-123abc")
2 .set_value("email", "youremail@example.com".into())
3 .add_private_attribute(Reference::new("email"))
4 .build()?;

When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

AI SDKs

Here are the configuration options for private context attributes in AI SDKs:

.NET AI

In the .NET AI SDK you can mark attributes as private when building the context object by calling Private() after setting the attribute on the context builder.

For example:

.NET AI SDK
1var context = Context.Builder("context-key-123abc")
2 .Set("email", "sandy@example.com")
3 .Private("email")
4 .Build();

When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Go AI

In the Go AI SDK you can mark attributes as private when building the context object by calling Private() after setting the attribute on the context builder.

For example:

Go AI SDK
1import (
2 "github.com/launchdarkly/go-sdk-common/v3/ldcontext"
3)
4
5context := ldcontext.NewBuilder("context-key-123abc").
6 Kind("organization").
7 Name("Global Health Services").
8 SetString("email", "info@globalhealthexample.com").
9 Private("email").
10 Build()

When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Node.js (server-side) AI

In the Node.js (server-side) AI SDK you can define a set of privateAttributes on the context object.

Here’s how:

1const context: LDContext = {
2 kind: 'user',
3 key: 'user-key-123abc',
4 email: 'sandy@example.com',
5 privateAttributes: ['email'],
6};

When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Python AI

In the Python AI SDK you can mark attributes as private when building the context object by calling the private builder method.

Here’s how:

Python AI SDK
1context = Context.builder("context-key-123abc") \
2 .set("email", "sandy@example.com") \
3 .private("email") \
4 .build()

When the SDK sends this context back to LaunchDarkly, it removes the email attribute.

Built with