Private attributes
Read time: 29 minutes
Last edited: Nov 15, 2024
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.
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.
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 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:
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.
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)
- Android
- C++ (client-side)
- Electron
- Flutter
- iOS
- JavaScript
- Node.js (client-side)
- React Native
- React Web: The React Web SDK relies on the JavaScript SDK for context-related functionality.
- Roku
.NET (client-side)
Expand .NET (client-side) code sample
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 theAllAttributesPrivate
method, which takes in a boolean parameter. Iftrue
, 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 thePrivateAttributes
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:
// All attributes marked privatevar configAllPrivate = Configuration.Builder("mobile-key-123abc", ConfigurationBuilder.AutoEnvAttributes.Enabled).AllAttributesPrivate(true).Build();LdClient client = LdClient.Init(configAllPrivate, context);// Two attributes marked privatevar configSomePrivate = Configuration.Builder("mobile-key-123abc").PrivateAttributes("email", "address").Build();LdClient 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:
var context = Context.Builder("context-key-123abc").Set("email", "sandy@example.com").Private("email").Build();
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
Android
Expand Android code sample
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:
// All attributes marked privateLDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled).mobileKey("mobile-key-123abc").events(Components.sendEvents().allAttributesPrivate(true)).build();// Two attributes marked privateLDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled).mobileKey("mobile-key-123abc").events(Components.sendEvents().privateAttributes("name", "group")).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:
LDContext context = LDContext.builder("context-key-123abc").set("email", "sandy@example.com").set("name", "Sandy").set("group", "Microsoft").privateAttributes("name", "group")
When the SDK sends this context back to LaunchDarkly, it removes the name
and group
attributes.
C++ (client-side)
Expand C++ (client-side) code sample
In the C++ SDK there are two ways to define private attributes for the LaunchDarkly client:
- When using the
ConfigBuilder
, you can callAllAttributesPrivate()
. 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 ofPrivateAttributes()
. If any context has an attribute named in this list, the SDK removes it before sending the context to LaunchDarkly.
Here's how:
/* sets all attributes private */auto config_builder = client_side::ConfigBuilder("mobile-key-123abc");config_builder.Events().AllAttributesPrivate(true);auto config_all_private = config_builder.Build();/* sets "email" and "address" private */auto config_builder = client_side::ConfigBuilder("mobile-key-123abc");config_builder.Events().PrivateAttributes({"email", "address"});auto configSomePrivate = config_builder.Build();
You can also define private attributes for a particular context by calling .SetPrivate()
in the ContextBuilder
.
Here's how:
auto context = ContextBuilder().Kind("user", "user-key-123abc").Name("Sandy Smith").SetPrivate("email", "sandy@example.com").Build();
To learn more, read ContextBuilder
.
Electron
Expand Electron code sample
To mark all user attributes except the key as private, use the allAttributesPrivate
option:
const user = {key: 'user-key-123abc',name: 'Sandy Smith',email: 'sandy@example.com'};const client = LDElectron.initialize('client-side-id-123abc', user, {allAttributesPrivate: true});
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:
const user = {key: 'user-key-123abc',name: 'Sandy Smith',email: 'sandy@example.com',privateAttributeNames: ['email']};const client = LDElectron.initialize('client-side-id-123abc', user, {privateAttributeNames: ['email']});
In the above example, the SDK sends only the key
and name
back to LaunchDarkly.
Flutter
Expand Flutter code sample
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.
final config = LDConfig(CredentialSource.fromEnvironment,AutoEnvAttributes.enabled,allAttributesPrivate: true, // all attributes marked privateglobalPrivateAttributes: ['user/email', 'user/group'], // two attributes marked private for the 'user' context kind)
You can also mark attributes as private when building the context object by using the private
optional parameter. For example:
final context = LDContextBuilder().kind('user', 'user-key-123abc'),.setString('name', 'Sandy').setString('email', 'sandy@example.com', private: true).setString('group', 'microsoft', private: true).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
Expand iOS code sample
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 theallContextAttributesPrivate
attribute totrue
. - When creating the LDConfig object, you can set the
privateContextAttributes
property to a list ofReference
s, 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:
// All attributes marked privateconfig = LDConfig(mobileKey: "mobile-key-123abc", autoEnvAttributes: .enabled)config.allContextAttributesPrivate = true// Two attributes marked privateconfig = LDConfig(mobileKey: "mobile-key-123abc", autoEnvAttributes: .enabled)config.privateContextAttributes = [Reference("email"), Reference("address")]
You can also mark attributes as private on a particular LDContext
instance, for example:
var contextBuilder = LDContextBuilder(key: "context-key-123abc")contextBuilder.trySetValue("name", .string("Sandy"))contextBuilder.trySetValue("group", .array([LDValue(stringLiteral: "microsoft")]))contextBuilder.addPrivateAttribute(Reference("name"))contextBuilder.addPrivateAttribute(Reference("group"))let context = try contextBuilder.build().get()
JavaScript
Expand JavaScript code sample
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:
const context = {kind: 'user',key: 'user-key-123abc',name: 'Sandy Smith',email: 'sandy@example.com'};// All attributes marked privateconst ldclient = ld.initialize('client-side-id-123abc', context, options = {allAttributesPrivate: true});// Two attributes marked privateconst ldclient = ld.initialize('client-side-id-123abc', context, options = {privateAttributes: ['email', 'name']});
In the context object, specify your array of attributes in the privateNames
field of the reserved _meta
property.
Here's how:
const context = {kind: 'user',key: 'context-key-123abc',name: 'Sandy Smith',email: 'sandy@example.com',_meta: {privateAttributes: ['email']}};const ldclient = ld.initialize('client-side-id-123abc', context, options = {privateAttributes: ['email']});
In the above example, the SDK sends only the context's key and name back to LaunchDarkly.
Node.js (client-side)
Expand Node.js (client-side) code sample
To mark all user attributes except the key as private in the Node.js SDK, you can use the allAttributesPrivate
option:
const context = {kind: 'user',key: 'user-key-123abc',name: 'Sandy Smith',email: 'sandy@example.com'};// All attributes marked privateconst client = ld.initialize('client-side-id-123abc', context, {allAttributesPrivate: true});// Two attributes marked privateconst client = ld.initialize('client-side-id-123abc', context, {privateAttributes: ['email', 'name']});
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:
const context = {kind: 'user',key: 'user-key-123abc',name: 'Sandy Smith',email: 'sandy@example.com'_meta: {privateAttributes: ['email']}};const client = ld.initialize('client-side-id-123abc', context, {privateAttributes: ['email']});
In the above example, the SDK sends only the context key and name back to LaunchDarkly.
React Native
Expand React Native code sample
You can configure this option in the configuration object, to apply to all contexts, either for all attributes or some attributes:
// All attributes marked privateconst options = {allAttributesPrivate: true}const client = new ReactNativeLDClient('mobile-key-123abc', AutoEnvAttributes.Enabled, options);// Two attributes marked privateconst options = {privateAttributes: ['email', 'address']}const 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:
const context = {kind: 'user',key: 'user-key-123abc',firstName: 'Sandy',lastName: 'Smith',email: 'sandy@example.com',address: {street: '123 Main St',city: 'Springfield'},_meta: {privateAttributes: ['email', '/address/street']}};
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
Expand Roku code sample
You can configure this option in the configuration object, to apply to all contexts, either for all attributes or some attributes:
' All attributes marked privateconfig = LaunchDarklyConfig("mobile-key-123abc", launchDarklyTaskNode)config.setAllAttributesPrivate(true)LaunchDarklySGInit(config, context)client = LaunchDarklySG(launchDarklyTaskNode)' Two attributes marked privateconfig = LaunchDarklyConfig("mobile-key-123abc", launchDarklyTaskNode)config.addPrivateAttribute("email")config.addPrivateAttribute("address")LaunchDarklySGInit(config, context)client = LaunchDarklySG(launchDarklyTaskNode)
You can also mark an attribute as private for a particular context:
' when creating a contextcontext = LaunchDarklyCreateContext({"kind": "user","key": "context-key-123-abc","email": "sandy@example.com","_meta": { privateAttributes: ["email"] }})' for an existing contextcontext.addPrivateAttribute("email")context.addPrivateAttribute("/address/street")
Server-side SDKs
Here are the configuration options for private context and user attributes in server-side SDKs:
- .NET (server-side)
- Apex
- C++ (server-side)
- Erlang
- Go
- Haskell
- Java
- Lua
- Node.js (server-side)
- PHP
- Python
- Ruby
- Rust
.NET (server-side)
Expand .NET (server-side) code sample
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 configureEvents
withAllAttributesPrivate
, which takes in a boolean parameter. Iftrue
, the SDK removes all attributes for all contexts before sending the context to LaunchDarkly, except the key. - Or, you can configure
Events
withPrivateAttributes
, 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 privatevar config = Configuration.Builder("sdk-key-123abc").Events(Components.SendEvents().AllAttributesPrivate(true) // defaults to false).Build();var client = new LDClient(config);// Two attributes marked as privatevar config = Configuration.Builder("sdk-key-123abc").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("context-key-123abc").Set("email", "sandy@example.com").Private("email").Build();
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
Apex
Expand Apex code sample
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('user-key-123abc').setFirstName('alice').setPrivateAttributeNames(privateAttributes).build();
C++ (server-side)
Expand C++ (server-side) code sample
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("sdk-key-123abc");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("sdk-key-123abc");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", "user-key-123abc").SetPrivate("email", "sandy@example.com").Build();
To learn more, read ContextBuilder
.
Erlang
Expand Erlang code sample
Here's how to set context attributes as private for all or just some contexts:
%% All attributes marked as privateldclient:start_instance("sdk-key-123abc", #{private_attributes => all}).%% Two attributes marked as privateldclient:start_instance("sdk-key-123abc", #{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
Expand Go code sample
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 contextsconfig.Events = ldcomponents.SendEvents().AllAttributesPrivate(true)// Or, make just the email and address attributes private for all contextsconfig.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("context-key-123abc").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
Expand Haskell code sample
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, useconfigSetAllAttributesPrivate
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 withconfigSetPrivateAttributeNames
. 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 privatemakeConfig "sdk-key-123abc" & configSetAllAttributesPrivate True-- Two attributes marked privateimport qualified Data.Set as Simport qualified LaunchDarkly.Server.Reference as RmakeConfig 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
Expand Java code sample
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 theallAttributesPrivate
method, which takes in a boolean parameter. Iftrue
, 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 theprivateAttributes
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 privateLDConfig configWithAllAttributesPrivate = new LDConfig.Builder().events(Components.sendEvents().allAttributesPrivate(true)).build();// Some attributes marked privateLDConfig 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("context-key-123abc").set("email", "sandy@example.com").privateAttributes("email").build();
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
Lua
Expand Lua code sample
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 privatelocal configAllPrivate = {events = {allAttributesPrivate = true}}-- sets "email" and "address" privatelocal 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 = "user-key-123abc",attributes = {firstName = "Sandy",lastName = "Smith",email = "sandy@example.com",groups = { "Google", "Microsoft" }},privateAttributes = { "email "}}})
To learn more, read clientInit
and makeContext
.
Node.js (server-side)
Expand Node.js (server-side) code sample
In the Node.js SDK there are two ways to define private attributes for the entire LaunchDarkly client:
- In the LaunchDarkly
LDOptions
, you can setallAttributesPrivate
totrue
. 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 ofprivateAttributes
. 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 privateconst options = {allAttributesPrivate: true};client = ld.init('sdk-key-123abc', options);// Two attributes marked privateconst options = {privateAttributes: ['email', 'address']};client = ld.init('sdk-key-123abc', 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: 'user-key-123abc',email: 'sandy@example.com',privateAttributes: ['email'],};
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
PHP
Expand PHP code sample
In the PHP SDK there are two ways to define private attributes for the entire LaunchDarkly client:
- In the LaunchDarkly
config
, you can setall_attributes_private
totrue
. 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 ofprivate_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('context-key-123abc')->set('email', 'sandy@example.com')->private('email')->build();
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
Python
Expand Python code sample
In the Python SDK there are two ways to define private attributes for the LaunchDarkly client:
- In the LaunchDarkly
config
, you can setall_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 inprivate_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 privateconfig = Config(all_attributes_private=True)# Two attributes marked privateconfig = 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("context-key-123abc") \.set("email", "sandy@example.com") \.private("email") \.build()
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
Ruby
Expand Ruby code sample
In the Ruby SDK there are two ways to define private attributes for the entire LaunchDarkly client:
- In the LaunchDarkly
config
, you can setall_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 privateconfig = LaunchDarkly::Config.new({all_attributes_private: true})# Two attributes marked privateconfig = 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: "user-key-123abc",kind: "user",firstName: "Sandy",lastName: "Smith",email: "sandy@example.com",groups: ["Google", "Microsoft"],_meta: {privateAttributes: ['email']}})
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
Rust
Expand Rust code sample
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 privatelet config_builder = ConfigBuilder::new("sdk-key-123abc");let mut processor_builder = EventProcessorBuilder::new();processor_builder.all_attributes_private(true););config_builder.event_processor(&processor_builder);// Two attributes marked privatelet config_builder = ConfigBuilder::new("sdk-key-123abc");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("context-key-123abc").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.
AI SDKs
Here are the configuration options for private context attributes in AI SDKs:
.NET (AI)
Expand .NET (AI) code sample
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:
var context = Context.Builder("context-key-123abc").Set("email", "sandy@example.com").Private("email").Build();
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
Node.js (AI)
Expand Node.js (AI) code sample
In the Node.js (AI) SDK you can define a set of privateAttributes
on the context object.
Here's how:
const context: LDContext = {kind: 'user',key: 'user-key-123abc',email: 'sandy@example.com',privateAttributes: ['email'],};
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.
Python (AI)
Expand Python (AI) code sample
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:
context = Context.builder("context-key-123abc") \.set("email", "sandy@example.com") \.private("email") \.build()
When the SDK sends this context back to LaunchDarkly, it removes the email
attribute.