No results for ""
EXPAND ALL
  • Home
  • API docs

Context instances

Read time: 3 minutes
Last edited: Nov 25, 2024

Overview

This topic includes information about context instances. Contexts are people, services, machines, or other resources that encounter feature flags in your product.

We refer to any unique combination of one or more contexts that have encountered a feature flag as a context instance.

Example context: Anna at Global Health Services

For example, suppose a hospital's employee app uses organization, device, and user contexts. When Anna from Global Health Services logs into your application from her Android in Springfield, that's recorded as one instance. When Anna logs into your app from her iPad in Midway, that's recorded as second instance. Even though Anna's user context appears in both, LaunchDarkly considers these two different context instances because they contain different combinations of context keys.

The two context instances are the combination of their associated contexts:

  • Anna, Springfield, Android device
  • Anna, Midway, iPad

Here is an example of what the data structure might look like for these two context instances, though each SDK sends context data to LaunchDarkly in a slightly different format:

// The first context instance
{
"kind": "multi",
"user": {
"key": "user-key-123abc",
"name": "Anna",
"email": "anna@globalhealthexample.com",
"jobFunction": "doctor"
},
"organization": {
"key": "org-key-123abc",
"name": "Springfield Global Health Services",
"address": {
"street": "123 Main Street",
"city": "Springfield"
}
},
"device": {
"key": "device-key-123abc",
"name": "Pixel 7",
"os": "Android 13"
}
}
// The second context instance
{
"kind": "multi",
"user": {
"key": "user-key-123abc",
"name": "Anna",
"email": "anna@globalhealthexample.com",
"jobFunction": "doctor"
},
"organization": {
"key": "org-key-456def",
"name": "Midway Global Health Services",
"address": {
"street": "456 1st Ave",
"city": "Midway"
}
},
"device": {
"key": "device-key-456def",
"name": "iPad",
"os": "iOS"
}
}

A context appearing alone, without any other associated contexts, is also considered a context instance.

For example, this stand-alone context and this multi-context also represent two context instances:

// The first context instance
{
"kind": "user",
"key": "user-key-123abc",
"name": "Anna",
"email": "anna@globalhealthexample.com",
"jobFunction": "doctor"
}
// The second context instance
{
"kind": "multi",
"user": {
"key": "user-key-123abc",
"name": "Anna",
"email": "anna@globalhealthexample.com",
"jobFunction": "doctor"
},
"organization": {
"key": "org-key-456def",
"name": "Midway Global Health Services",
"address": {
"street": "456 1st Ave",
"city": "Midway"
}
},
"device": {
"key": "device-key-456def",
"name": "iPad",
"os": "iOS"
}
}

Context instance versions

Two different SDKs might encounter the same context, as defined by their unique combination of kind and key, with different context attributes. Because they have the same unique combination of kind and key, the contexts are not considered separate contexts or separate context instances. Instead, they are two different versions of the same context instance.

For example, depending on how your application is set up, LaunchDarkly may record one or more context instance versions each time Anna logs in. If your application uses both the Android SDK and the JavaScript SDK in different places, and Anna logs in from both places, then you'll see two different context instance versions: one from Anna from the Android SDK, and another from Anna from the JavaScript SDK.

This illustration shows example contexts, context instances, and context instance versions:

An example of associated contexts, context instances, and context instance versions.
An example of associated contexts, context instances, and context instance versions.

You can view context instances, context instance versions, and expected flag variations on the Context details page.

Here is what Anna's context details page would look like. Two instances display in the "Instances" section, and this context instance version is from "JSClient":

An image of the context details page.
An image of the context details page.

To learn more, read The context details page.