Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

getFlagReason always undefined with allFlagsState response #235

Closed
ClementLevesque opened this issue Feb 18, 2022 · 3 comments
Closed

getFlagReason always undefined with allFlagsState response #235

ClementLevesque opened this issue Feb 18, 2022 · 3 comments

Comments

@ClementLevesque
Copy link

Is this a support request? No.

Describe the bug

The method allFlagsState returns a Promise resolved by an object on which getFlagReason(key) returns always undefined :

const flagsState = await featureFlagClientInt.allFlagsState({ key });

// flagsState.getFlagReason(key) === undefined
// flagsState.allValues() & flagsState.getFlagValue() are ok 

Whereas featureDetail which returns the proper object :

const { reason, value } = await featureFlagClientInt.featureDetail(featureKey, { key }, false);
// reason.kind === 'OFF' || 'RULE_MATCH' etc.

To reproduce

  • Create a feature flag in the dashboard
  • Instanciate the LaunchDarklyClient
  • Call allFlagsState on that client

Expected behavior
getFlagReason should return a LDEvaluationReason object type.

Logs
See above.

SDK version
Current sdk version: launchdarkly-node-server-sdk: "5.13.4"

Language version, developer tools
NodeJS 16.1.0

OS/platform
On local env, Mac book pro M1.

Additional context
Add any other context about the problem here.

@kinyoklion
Copy link
Member

kinyoklion commented Feb 18, 2022

Hello @ClementLevesque,

By default allFlagsState does not include reasons for all flags. You can change the behavior by using LDFlagsStateOptions to indicate you want reasons.

await ldClient.allFlagsState({key}, {withReasons: true});

Thank you,
Ryan

@eli-darkly
Copy link
Contributor

Yes, that's what the API docs for getFlagReason mean when they say "it will be null if reasons were not recorded". Reasons are only recorded if you use the option Ryan mentioned.

As background, here's why the default is not to capture reasons. The most common use case for allFlagsState is to produce bootstrap data for initializing the JS SDK. That data will have to be passed in some way to the front end, such as by embedding it in a hidden HTML component, so it's desirable to not make it any bigger than necessary. And most front-end code that uses the JS SDK does not use evaluation reasons— getting them is an opt-in feature for client-side SDKs, even if you are connecting directly to LD and not using bootstrap data. So the reasons are omitted from that data by default.

eli-darkly added a commit that referenced this issue Feb 19, 2022
@ClementLevesque
Copy link
Author

It works ! Thanks a lot for your help and precious and detailed answer. I have to admit that the API docs could be more explicit about this option 😉

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants