Built-in attributes
Read time: 2 minutes
Last edited: Nov 25, 2024
Overview
This topic explains what LaunchDarkly's built-in attributes are and how to configure them.
LaunchDarkly allows you to target contexts based on built-in attributes. To learn more, read Target with flags.
Use built-in attributes
The built-in attributes are kind, key, name, and anonymous. Kind, key, and name attributes must be strings, and anonymous attributes must be booleans. You can define additional attributes for a context by passing in a name and value for each.
The context kind and key are the only mandatory attributes. All other attributes are optional.
Some SDKs will automatically set the kind to "user" if you do not provide a value. Some client-side SDKs will automatically generate the key if the anonymous attribute is set to true.
Here is a table explaining LaunchDarkly's built-in attributes:
Attribute name | Attribute example value | Notes |
---|---|---|
kind | "user" | The context kind. Required for evaluation. The combination of kind and key must be unique for each context. You can create context kinds either from the Contexts list or by evaluating a context using a LaunchDarkly SDK. |
key | "context-key-123abc" | Required for evaluation. The combination of kind and key must be unique for each context. Some client-side SDKs will generate this for you if anonymous is set to true. |
name | "Sandy Smith" | This attribute is optional, but we recommend including it if you need to target flags to individual contexts. |
anonymous | true | This attribute is optional. If set, this boolean attribute prevents the context from appearing in the Contexts list. If the anonymous attribute is set to true , LaunchDarkly treats the context as anonymous. |
Here is an example of a context with built-in attribute values, though each SDK sends context data to LaunchDarkly in a slightly different format:
You can structure your context keys so they are both searchable and unique. To do this, we suggest adding a searchable term to the beginning of the key, followed by a unique ID. For example, if you wanted to easily search users that encountered a specific service, you could structure the key as follows: service_name:uuid
.
Alternatively, you can set unique identifiers for contexts in your SDK configuration. To learn more, read Application metadata configuration.
You can view a context's attributes by clicking on the individual context from the Contexts list.
You can also use the REST API: Get contexts, Search for contexts, Get context attribute names, Get context attribute values