feat: Populate OpenFeature flag metadata from the evaluation reason - #1869
feat: Populate OpenFeature flag metadata from the evaluation reason#1869kinyoklion wants to merge 2 commits into
Conversation
Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
@launchdarkly/js-sdk-common size report |
|
@launchdarkly/browser size report |
|
@launchdarkly/js-client-sdk size report |
|
@launchdarkly/js-client-sdk-common size report |
|
|
||
| import type { LDEvaluationDetail } from '@launchdarkly/js-sdk-common'; | ||
|
|
||
| const VARIATION_INDEX_KEY = 'variationIndex'; |
There was a problem hiding this comment.
Could we not use typing here? Instead of constants?
There was a problem hiding this comment.
Yes — replaced the constants with an exported LDFlagMetadata type (FlagMetadata intersected with the documented LaunchDarkly keys), so the keys and their value types are checked at the assignment sites and the metadata shape is now documented in the API reference. Package lint, build, and tests pass.
…stants Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
Populates OpenFeature flag metadata from the LaunchDarkly evaluation reason so consumers (and the OpenFeature/OTel telemetry hooks) can read experiment, rule, prerequisite, and Big Segments information.
variationIndex,inExperiment,ruleIndex,ruleId,prerequisiteKey,bigSegmentsStatus; each is omitted when it does not apply.@cursor review
Requirements
Implementation details
translateResultnow builds aFlagMetadataobject fromLDEvaluationDetail:variationIndexis included only when the SDK returned a variation, so default/error evaluations omit it.inExperimentis emitted only whentrue, rather than emittingfalsefor every non-experiment evaluation.ruleIndex/ruleId,prerequisiteKey, andbigSegmentsStatusare copied through when the reason provides them.Key names are named constants so they cannot drift from the spec.
Backend-only change; no UI, so no screenshots or staging preview apply.
Testing:
yarn workspace @launchdarkly/openfeature-js-server-common testand... lint, plusyarn workspace @launchdarkly/openfeature-node-server test. The existingBaseOpenFeatureProviderresult assertions were updated for the addedflagMetadatafield.Describe alternatives you've considered
Emitting the full reason object under a single nested key was rejected — OpenFeature flag metadata values must be scalars, and flat keys are what the spec draft standardizes across providers.
Link to Devin session: https://app.devin.ai/sessions/0c452d209ec54b068ba120b4c92b8f6c
Requested by: @kinyoklion
Note
Overview
OpenFeature resolution results from the shared server provider now include LaunchDarkly-specific
flagMetadataon every successful translation path, built fromLDEvaluationDetailintranslateResult.translateResultmaps optional scalar keys when they apply:variationIndex(skipped for null/missing variation),inExperiment(only when true), plusruleIndex/ruleId,prerequisiteKey, andbigSegmentsStatusfrom the evaluation reason. TheLDFlagMetadatatype is exported from@launchdarkly/openfeature-js-server-common, so Node and future server providers inherit the behavior automatically.The Node OpenFeature README adds a Flag Metadata section documenting the keys and a short usage example. Tests cover metadata shaping and update provider integration expectations to include
flagMetadata.Reviewed by Cursor Bugbot for commit 905a315. Bugbot is set up for automated code reviews on this repo. Configure here.