Skip to content

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

Merged
kinyoklion merged 2 commits into
mainfrom
devin/java-flag-metadata
Aug 25, 2026
Merged

feat: Populate OpenFeature flag metadata from the evaluation reason#56
kinyoklion merged 2 commits into
mainfrom
devin/java-flag-metadata

Conversation

@kinyoklion

@kinyoklion kinyoklion commented Aug 19, 2026

Copy link
Copy Markdown
Member

The provider discarded everything in the LaunchDarkly evaluation reason that did not fit into the OpenFeature reason string, so OpenFeature users could not tell that an evaluation was part of an experiment; the reason detail is now exposed as OpenFeature flag metadata.

  • ProviderEvaluation.flagMetadata now carries variationIndex, inExperiment, ruleIndex, ruleId, prerequisiteKey, and bigSegmentsStatus
  • Each entry is only present when it applies to the evaluation, so callers must null-check — inExperiment in particular is absent rather than false for non-experiment evaluations
  • Key names match the LaunchDarkly reason field names and the attribute names used by the LaunchDarkly OpenTelemetry hooks
  • Documented the keys in the README

@cursor review

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

Related issues

None; this is one of several gaps found while auditing the LaunchDarkly OpenFeature providers against the OpenFeature specification.

Describe the solution you've provided

EvaluationDetailConverter.getProviderEvaluation builds an ImmutableMetadata from the EvaluationReason. Both entry points (typed values and LDValue results) go through it, so object and array evaluations get metadata too.

variationIndex duplicates the information in variant, but as an integer rather than a stringified index, which is what consumers reading metadata for telemetry want. It is omitted along with variant when the SDK returned the default value.

The OpenFeature telemetry conventions only reserve contextId, flagSetId, and version; none of the three map to a LaunchDarkly concept available on the evaluation detail (contextId would need the canonical context key rather than the reason, and could be added separately). Everything here is therefore LaunchDarkly-specific, named after the reason fields so it lines up with EvaluationReason and with the feature_flag.result.* attributes the LaunchDarkly OTel hook emits.

Describe alternatives you've considered

  • A single nested reason structure: ImmutableMetadata only holds scalars, and flat keys are what telemetry hooks read.
  • Always emitting inExperiment: false: cheap for consumers, but it makes the metadata claim knowledge about evaluations where the reason carries none.

Additional context

./gradlew test javadoc passes, including new cases per metadata entry and one covering object results. Nothing outside the converter changes. No visual preview applies — this is a server-side provider change.

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


Note

Overview
OpenFeature evaluations now expose LaunchDarkly-specific details on ProviderEvaluation.flagMetadata, so consumers can see experiment participation, rule matches, prerequisites, and Big Segments status without parsing the reason string alone.

EvaluationDetailConverter builds ImmutableMetadata from each EvaluationReason and attaches it on every conversion path (typed values and LDValue object/array results). Keys are included only when they apply: variationIndex (integer, omitted for default values), inExperiment (only when true), ruleIndex/ruleId for rule matches, prerequisiteKey, and bigSegmentsStatus. The README adds a Flag Metadata table describing these fields.

Reviewed by Cursor Bugbot for commit c93fd2c. 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

private static ImmutableMetadata FlagMetadata(EvaluationReason reason, boolean isDefault, int variationIndex) {
var builder = ImmutableMetadata.builder();
if (!isDefault) {
builder.addInteger("variationIndex", 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.

We should move these names to defined constants instead of being inline.

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.

Done in c93fd2c — the keys are now private static final constants on EvaluationDetailConverter. I'll mirror the same constant treatment in the other providers, and Ryan asked for an sdk-specs spec defining these names, so the spec will be the source of truth for them.

Co-Authored-By: rlamb@launchdarkly.com <4955475+kinyoklion@users.noreply.github.com>
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>
@kinyoklion
kinyoklion marked this pull request as ready for review August 24, 2026 20:53
@kinyoklion
kinyoklion requested a review from a team as a code owner August 24, 2026 20:53
kinyoklion added a commit to launchdarkly/openfeature-dotnet-server that referenced this pull request Aug 25, 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 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](launchdarkly/openfeature-java-server#56);
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**

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

```csharp
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.
</details>

@cursor review


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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> **OpenFeature evaluation results now carry LaunchDarkly-specific
metadata** on `ResolutionDetails.FlagMetadata`, so hooks (e.g.
OpenTelemetry) can read experiment, rule, and segment context without
parsing the reason string alone.
> 
> `EvaluationDetailExtensions` maps `EvaluationReason` and variation
index into flat keys—`variationIndex`, `inExperiment`, `ruleIndex`,
`ruleId`, `prerequisiteKey`, and `bigSegmentsStatus` (as JSON-style
status strings)—and passes that metadata on both successful and error
conversions in `ToResolutionDetails`. Keys are **omitted when they do
not apply**, not set to defaults.
> 
> The README adds a **Flag Metadata** section (key table and
`GetBooleanDetailsAsync` example). Tests cover each key, omission
behavior, and structure/`Value` evaluation paths.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
1a6b4cd. 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>
@kinyoklion
kinyoklion merged commit 153eaa3 into main Aug 25, 2026
8 checks passed
@kinyoklion
kinyoklion deleted the devin/java-flag-metadata branch August 25, 2026 16:24
kinyoklion added a commit to launchdarkly/openfeature-python-server that referenced this pull request Aug 25, 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)
and
[openfeature-dotnet-server#61](launchdarkly/openfeature-dotnet-server#61);
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` now builds `flag_metadata` from the
LaunchDarkly reason dictionary:

```python
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.
</details>

@cursor review


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

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> OpenFeature evaluation details now include LaunchDarkly-specific
fields on `flag_metadata`, so hooks (including OpenTelemetry) can read
experiment, rule, and related evaluation info that has no OpenFeature
equivalent.
> 
> `ResolutionDetailsConverter` maps `variationIndex`, `inExperiment`,
`ruleIndex`, `ruleId`, `prerequisiteKey`, and `bigSegmentsStatus` from
the LD reason. Keys are omitted when they do not apply (including
`inExperiment` when false, and `variationIndex` for default values).
README documents the keys.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
a43597d. 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>
kinyoklion pushed a commit that referenced this pull request Aug 25, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.2.0](1.1.3...1.2.0)
(2026-08-25)


### Features

* Deprecate the provider getState method
([#55](#55))
([1f71ef3](1f71ef3))
* Populate OpenFeature flag metadata from the evaluation reason
([#56](#56))
([153eaa3](153eaa3))


### Bug Fixes

* Synchronize provider state access on the state lock
([#54](#54))
([ebe9513](ebe9513))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Overview**
> **Release Please** bumps the library from **1.1.3** to **1.2.0** in
`gradle.properties` and `.release-please-manifest.json`, and adds the
**1.2.0** section to `CHANGELOG.md`. No runtime code changes in this
diff.
> 
> The published **1.2.0** release (already on `main`) includes:
**deprecated** `Provider.getState()` with guidance to use
`Client.getProviderState()`; **flag metadata** on evaluations derived
from LaunchDarkly evaluation reason fields; and **thread-safe** provider
state reads/writes via synchronization on the state lock.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
a86744b. 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: github-actions[bot] <41898282+github-actions[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.

2 participants