You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+89-3Lines changed: 89 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,11 +50,97 @@ For information on using the OpenFeature client please refer to the [OpenFeature
50
50
51
51
## OpenFeature Specific Considerations
52
52
53
-
When evaluating a `User` with the LaunchDarkly Server-Side SDK for .NET a string `key` attribute would normally be required. When using OpenFeature the `targetingKey` attribute should be used instead of `key`. If a `key` attribute is provided in the `EvaluationContext`, then it will be discarded in favor of `targetingKey`. If a `targetingKey` is not provided, or if the `EvaluationContext` is omitted entirely, then the `defaultValue` will be returned from OpenFeature evaluation methods.
53
+
LaunchDarkly evaluates contexts, and it can either evaluate a single-context, or a multi-context. When using OpenFeature both single and multi-contexts must be encoded into a single `EvaluationContext`. This is accomplished by looking for an attribute named `kind` in the `EvaluationContext`.
54
54
55
-
Other fields normally included in a `User` may be added to the `EvaluationContext`. Any `custom` attributes can be added to the top level of the evaluation context, and they will operate as if they were `custom` attributes on an `User`. Attributes which are typically top level on an `LDUser` should be of the same types that are specified for a `User` or they will not operate as intended.
55
+
There are 4 different scenarios related to the `kind`:
56
+
1. There is no `kind` attribute. In this case the provider will treat the context as a single context containing a "user" kind.
57
+
2. There is a `kind` attribute, and the value of that attribute is "multi". This will indicate to the provider that the context is a multi-context.
58
+
3. There is a `kind` attribute, and the value of that attribute is a string other than "multi". This will indicate to the provider a single context of the kind specified.
59
+
4. There is a `kind` attribute, and the attribute is not a string. In this case the value of the attribute will be discarded, and the context will be treated as a "user". An error message will be logged.
56
60
57
-
If a top level `custom` attribute is defined on the `EvaluationContext`, then that will be a `custom` attribute inside `custom` for a `User`.
61
+
The `kind` attribute should be a string containing only contain ASCII letters, numbers, `.`, `_` or `-`.
62
+
63
+
The OpenFeature specification allows for an optional targeting key, but LaunchDarkly requires a key for evaluation. A targeting key must be specified for each context being evaluated. It may be specified using either `targetingKey`, as it is in the OpenFeature specification, or `key`, which is the typical LaunchDarkly identifier for the targeting key. If a `targetingKey` and a `key` are specified, then the `targetingKey` will take precedence.
64
+
65
+
There are several other attributes which have special functionality within a single or multi-context.
66
+
- A key of `privateAttributes`. Must be an array of string values. [Equivalent to the 'Private' builder method in the SDK.](https://launchdarkly.github.io/dotnet-server-sdk/api/LaunchDarkly.Sdk.ContextBuilder.html#LaunchDarkly_Sdk_ContextBuilder_Private_System_String___)
67
+
- A key of `anonymous`. Must be a boolean value. [Equivalent to the 'Anonymous' builder method in the SDK.](https://launchdarkly.github.io/dotnet-server-sdk/api/LaunchDarkly.Sdk.Context.html#LaunchDarkly_Sdk_Context_Anonymous)
68
+
- A key of `name`. Must be a string. [Equivalent to the 'Name' builder method in the SDK.](https://launchdarkly.github.io/dotnet-server-sdk/api/LaunchDarkly.Sdk.ContextBuilder.html#LaunchDarkly_Sdk_ContextBuilder_Name_System_String_)
69
+
70
+
### Examples
71
+
72
+
#### A single user context
73
+
74
+
```csharp
75
+
varevaluationContext=EvaluationContext.Builder()
76
+
.Set("targetingKey", "my-user-key") // Could also use "key" instead of "targetingKey".
77
+
.Build();
78
+
```
79
+
80
+
#### A single context of kind "organization"
81
+
82
+
```csharp
83
+
varevaluationContext=EvaluationContext.Builder()
84
+
.Set("kind", "organization")
85
+
.Set("targetingKey", "my-org-key") // Could also use "key" instead of "targetingKey".
86
+
.Build();
87
+
```
88
+
89
+
#### A multi-context containing a "user" and an "organization"
90
+
91
+
```csharp
92
+
varevaluationContext=EvaluationContext.Builder()
93
+
.Set("kind", "multi") // Lets the provider know this is a multi-context
94
+
// Every other top level attribute should be a structure representing
95
+
// individual contexts of the multi-context.
96
+
// (non-conforming attributes will be ignored and a warning logged).
0 commit comments