Skip to content

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

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

feat: Populate OpenFeature flag metadata from the evaluation reason#61
kinyoklion wants to merge 1 commit into
mainfrom
devin/dotnet-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 names of 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; 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

EvaluationDetailExtensions gains a ToFlagMetadata extension on EvaluationReason, and both the success and error paths of ToResolutionDetails pass its result as flagMetadata:

private static ImmutableMetadata ToFlagMetadata(this EvaluationReason reason, int? variationIndex)
{
    var metadata = new Dictionary<string, object>();
    if (variationIndex.HasValue) metadata[VariationIndexKey] = variationIndex.Value;
    if (reason.InExperiment) metadata[InExperimentKey] = true;
    if (reason.RuleIndex.HasValue) metadata[RuleIndexKey] = reason.RuleIndex.Value;
    // ...
    return new ImmutableMetadata(metadata);
}

ruleIndex and ruleId are gated on the reason actually carrying them rather than on the reason kind, so no key is written from a sentinel value.

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

Describe alternatives you've considered

A single nested reason structure would be closer to the LaunchDarkly evaluation reason, but ImmutableMetadata only holds scalar values, so the flat keys are the only shape available.

Testing

BUILDFRAMEWORKS=netstandard2.0 dotnet build src/LaunchDarkly.OpenFeature.ServerProvider -f netstandard2.0
BUILDFRAMEWORKS=net8.0 dotnet test test/LaunchDarkly.OpenFeature.ServerProvider.Tests -f net8.0

All tests pass, including 8 new cases covering each key, the omissions, and structure evaluations.

Additional context

net471 could not be exercised locally because Mono is not installed on the build machine; CI covers it.

@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

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

kinyoklion added a commit to launchdarkly/openfeature-ruby-server that referenced this pull request Aug 21, 2026
)

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](launchdarkly/openfeature-java-server#56),
[openfeature-dotnet-server#61](launchdarkly/openfeature-dotnet-server#61)
and
[openfeature-python-server#53](launchdarkly/openfeature-python-server#53);
the naming is being defined in an [sdk-specs
spec](launchdarkly/sdk-specs#253).

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

<details>
<summary>Implementation details</summary>

**Requirements**

- [x] I have added test coverage for new or changed functionality
- [x] I have followed the repository's pull request submission
guidelines
- [x] I have validated my changes against all supported platform
versions

**Describe the solution you've provided**

`ResolutionDetailsConverter#to_resolution_details` now passes
`flag_metadata`:

```ruby
flag_metadata: flag_metadata(reason, is_default ? nil : variation_index)
```

Each entry is gated on the corresponding reason field being present
rather than on the reason kind, so no key is written from a sentinel
value. `big_segments_status` is a symbol in the Ruby SDK, so it is
stringified to keep the metadata value types consistent with the other
providers.

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

**Describe alternatives you've considered**

Exposing the reason object itself as one metadata entry would be closer
to the LaunchDarkly shape, but OpenFeature flag metadata values are
scalars, so the flat keys are the only available shape.

**Additional context**

```
docker run --rm -v "$PWD":/app -w /app ruby:3.4 bash -c "bundle install && bundle exec rake"
```

61 examples, 0 failures; RuboCop clean. 7 new examples cover each key
and the omissions.
</details>

@cursor review


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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> OpenFeature evaluations now include LaunchDarkly-only details on
`flag_metadata`, so hooks (including OpenTelemetry) can read them.
> 
> `ResolutionDetailsConverter` maps `variationIndex`, `inExperiment`,
`ruleIndex`, `ruleId`, `prerequisiteKey`, and `bigSegmentsStatus` from
the evaluation reason. Keys are omitted when they do not apply
(including `inExperiment` when false, and `variationIndex` for default
values). `bigSegmentsStatus` is stringified.
> 
> The README documents the keys and a usage example. Specs cover each
field and the omission cases.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
deaf178. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant