-
Notifications
You must be signed in to change notification settings - Fork 51
Closed
Description
The typescript examples in the OpenFeature docs show this snippet:
// add a value to the context
await OpenFeature.setContext({ myUserData: 'myUserValue' });
// the context is used for all feature flag evaluations automatically.
const boolValue = await client.getBooleanValue('boolFlag', false);Leading one to believe that a similar approach would work with the Java SDK, however this is not true and it's very surprising behavior if you are used to things like MDC context in Log4j.
One would expect this to work:
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
Map<String, Value> transactionAttrs = new HashMap<>();
transactionAttrs.put("userId", new Value("userId"));
EvaluationContext transactionCtx = new ImmutableContext(transactionAttrs);
api.setTransactionContext(apiCtx);
api.client.getBooleanValue("my-flag", false)but instead you must do
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
Map<String, Value> transactionAttrs = new HashMap<>();
transactionAttrs.put("userId", new Value("userId"));
EvaluationContext transactionCtx = new ImmutableContext(transactionAttrs);
api.setTransactionContext(apiCtx);
api.client.getBooleanValue("my-flag", false, api.getEvaluationContext)Which IMO is surprising and inconsistent behavior and makes context propagation less than useful.
Metadata
Metadata
Assignees
Labels
No labels