Skip to content

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

Draft
kinyoklion wants to merge 1 commit into
mainfrom
devin/python-flag-metadata
Draft

feat: Populate OpenFeature flag metadata from the evaluation reason#53
kinyoklion wants to merge 1 commit into
mainfrom
devin/python-flag-metadata

Conversation

@kinyoklion

Copy link
Copy Markdown
Member

Populates OpenFeature flag metadata with the LaunchDarkly specific parts of the evaluation result, so hooks (including the OpenTelemetry hook) can read them.

  • Keys mirror the evaluation reason fields: variationIndex, inExperiment, ruleIndex, ruleId, prerequisiteKey, bigSegmentsStatus.
  • Each key is omitted rather than default-valued when it does not apply, so a consumer can distinguish "not in an experiment" from "no information".
  • Matches openfeature-java-server#56 and openfeature-dotnet-server#61; the naming is being defined in an sdk-specs spec.

No screenshots or staging preview apply - this is a server-side library change with no UI.

Implementation details

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

Describe the solution you've provided

ResolutionDetailsConverter now builds flag_metadata from the LaunchDarkly reason dictionary:

flag_metadata=self.__to_flag_metadata(reason, variation_index if not is_default else None)

Each reason field is read defensively with an isinstance check, since the reason is a plain dictionary, so a malformed reason cannot put an unexpected type into the metadata. variationIndex uses the same default-value check that already gates variant.

The README gains a "Flag Metadata" section documenting the keys.

Describe alternatives you've considered

Passing the whole reason dictionary through as a single reason metadata entry would be closer to the LaunchDarkly shape, but FlagMetadata values are scalars, so the flat keys are the only available shape.

Additional context

poetry run pytest
poetry run mypy ld_openfeature tests

All tests pass, including 7 new cases covering each key and the omissions. make test/make lint currently fail on poetry install on main as well, because poetry.lock is out of date relative to pyproject.toml - unrelated to this change.

@cursor review

Link to Devin session: https://app.devin.ai/sessions/0c452d209ec54b068ba120b4c92b8f6c
Requested by: @kinyoklion

Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
@kinyoklion kinyoklion self-assigned this Aug 19, 2026
@devin-ai-integration devin-ai-integration Bot added the devin-pr Pull request created by Devin AI label 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devin-pr Pull request created by Devin AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant