Skip to content

Add evaluation detail methods, updated providers, update README - #22

Merged
toddbaert merged 8 commits into
mainfrom
detail-methods
Apr 19, 2022
Merged

toddbaert merged 8 commits into
mainfrom
detail-methods

Conversation

@toddbaert

Copy link
Copy Markdown
Member

This is a first pass at an API for getting additional flag evaluation details (see here for the structure of the details and here for an example of one of the new methods).

Some, but not all providers are currently able to provide this additional metadata, so the presence of this data is "best effort". The precise semantics of the various properties are certainly up for discussion (the errorCodes and reasons for example). The idea is to support mapping custom provider codes and errors to well-defined enumerations in OpenFeature (see the the mapping in the LaunchDarkly demo provider for example).

Many of the field names in the FlagEvaluationDetails schema are also used in the proposed OTel semantics.

I've also update the README in the root, which had become somewhat out of date.

Comment on lines +69 to +82
* Flagsmith differentiates between flag activity and boolean flag values, so in this provider,`isEnabled` is NOT a proxy to `getBooleanValue`.
*/
async isEnabledEvaluation(
flagKey: string,
_defaultValue: boolean,
userId: string | undefined,
_options?: FlagEvaluationOptions
): Promise<boolean> {
userId: string | undefined
): Promise<ProviderEvaluation<boolean>> {
const value = userId
? await flagsmith.hasFeature(flagId, userId)
: await flagsmith.hasFeature(flagId);
if (typeof value === 'boolean') {
return value;
} else {
throw new FlagTypeError(
this.getFlagTypeErrorMessage(flagId, value, 'boolean')
);
}
? await flagsmith.hasFeature(flagKey, userId)
: await flagsmith.hasFeature(flagKey);
return {
value,
reason: Reason.UNKNOWN,
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an important point generally. Some feature flag systems make a distinction between flag activity ("on" or "off") and flag boolean payloads. In other words, it's entirely possible that it's idiomatic for some providers to treat isEnabled() differently than getBooleanValue().

Comment on lines +181 to +197
private mapReason(reason: LDEvaluationReason) {
switch (reason.kind) {
case 'OFF':
return Reason.DISABLED;
case 'FALLTHROUGH':
return Reason.DEFAULT;
case 'TARGET_MATCH':
return Reason.TARGETING_MATCH;
case 'RULE_MATCH':
return Reason.TARGETING_MATCH;
case 'PREREQUISITE_FAILED':
return Reason.DEFAULT;
case 'ERROR':
return Reason.ERROR;
default:
return Reason.UNKNOWN;
}

@toddbaert toddbaert Apr 13, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An attempt to reasonably map LD reasons to OpenFeature reasons. Ideally, later, most providers will support this additional data. For now, only LaunchDarkly provides this additional info in their SDK.

Comment thread packages/api/src/main.ts Resolved
@toddbaert
toddbaert force-pushed the detail-methods branch 4 times, most recently from 51975f9 to 8fb9e1c Compare April 13, 2022 14:59
@toddbaert
toddbaert merged commit 3667039 into main Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants