Skip to content

feat: Populate OpenFeature flag metadata from the evaluation reason - #1869

Open
kinyoklion wants to merge 2 commits into
mainfrom
devin/node-flag-metadata
Open

feat: Populate OpenFeature flag metadata from the evaluation reason#1869
kinyoklion wants to merge 2 commits into
mainfrom
devin/node-flag-metadata

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Aug 19, 2026

Copy link
Copy Markdown
Member

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.

  • Adds flat, camelCase keys variationIndex, inExperiment, ruleIndex, ruleId, prerequisiteKey, bigSegmentsStatus; each is omitted when it does not apply.
  • Applies to the shared server translator, so it covers the Node provider (and any future server provider built on it).
  • Matches the behavior now specified in sdk-specs#253 and implemented in the Java, .NET, Python, and Ruby providers.
  • Documents the keys in the Node provider README.

@cursor review

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions
Implementation details

translateResult now builds a FlagMetadata object from LDEvaluationDetail:

  • variationIndex is included only when the SDK returned a variation, so default/error evaluations omit it.
  • inExperiment is emitted only when true, rather than emitting false for every non-experiment evaluation.
  • ruleIndex/ruleId, prerequisiteKey, and bigSegmentsStatus are 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 test and ... lint, plus yarn workspace @launchdarkly/openfeature-node-server test. The existing BaseOpenFeatureProvider result assertions were updated for the added flagMetadata field.

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 flagMetadata on every successful translation path, built from LDEvaluationDetail in translateResult.

translateResult maps optional scalar keys when they apply: variationIndex (skipped for null/missing variation), inExperiment (only when true), plus ruleIndex/ruleId, prerequisiteKey, and bigSegmentsStatus from the evaluation reason. The LDFlagMetadata type 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.

Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
@kinyoklion kinyoklion self-assigned this Aug 19, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration devin-ai-integration Bot added the devin-pr PRs created by Devin AI label Aug 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 26360 bytes
Compressed size limit: 29000
Uncompressed size: 129188 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 179887 bytes
Compressed size limit: 200000
Uncompressed size: 833430 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 32444 bytes
Compressed size limit: 34000
Uncompressed size: 116232 bytes

@github-actions

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 41502 bytes
Compressed size limit: 44000
Uncompressed size: 224541 bytes


import type { LDEvaluationDetail } from '@launchdarkly/js-sdk-common';

const VARIATION_INDEX_KEY = 'variationIndex';

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.

Could we not use typing here? Instead of constants?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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>
@kinyoklion
kinyoklion marked this pull request as ready for review August 24, 2026 21:01
@kinyoklion
kinyoklion requested a review from a team as a code owner August 24, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin-pr PRs created by Devin AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant