Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ This matrix mirrors the [feature matrix of the OpenFeature SDK for Ruby](https:/
| ✅ | Tracking | `track` sends a LaunchDarkly custom event for the evaluation context, with the tracking event value and remaining details attached. |
| ✅ | Transaction Context Propagation | Provided by the OpenFeature SDK, which merges the transaction context into the evaluation context before the provider is called; no provider support is required. |
| ✅ | Extending | This provider is itself an extension of the OpenFeature SDK. The underlying LaunchDarkly client is available through `provider.client` for functionality with no OpenFeature equivalent. |
| ✅ | Flag metadata | LaunchDarkly evaluation reason details are returned as OpenFeature flag metadata. See [Flag Metadata](#flag-metadata). |
| ✅ | Flag metadata | LaunchDarkly evaluation reason details, including `overrideAffected`, are returned as OpenFeature flag metadata. See [Flag Metadata](#flag-metadata). |

<sub>Supported: ✅ | Partially supported: ⚠️ | Not supported: ❌</sub>

Expand Down Expand Up @@ -176,6 +176,7 @@ Evaluations include flag metadata for the LaunchDarkly specific parts of the eva
|---------------------|---------|--------------------------------------------------------------------|
| `variationIndex` | integer | The index of the returned variation. Absent for default values. |
| `inExperiment` | boolean | Present, and `true`, when the evaluation was part of an experiment. |
| `overrideAffected` | boolean | Present, and `true`, when a flag override affected the evaluation. |
| `ruleIndex` | integer | The index of the rule that matched. |
| `ruleId` | string | The identifier of the rule that matched. |
| `prerequisiteKey` | string | The key of the prerequisite flag that failed. |
Expand Down
2 changes: 1 addition & 1 deletion launchdarkly-openfeature-server-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency "launchdarkly-server-sdk", "~> 8.19"
spec.add_runtime_dependency "launchdarkly-server-sdk", "~> 8.20"
spec.add_runtime_dependency "openfeature-sdk", ">= 0.6.1", "< 0.9"

# For more information and examples about making a new gem, check out our
Expand Down
6 changes: 4 additions & 2 deletions lib/ldclient-openfeature/impl/details_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ module Impl
class ResolutionDetailsConverter
VARIATION_INDEX_KEY = 'variationIndex'
IN_EXPERIMENT_KEY = 'inExperiment'
OVERRIDE_AFFECTED_KEY = 'overrideAffected'
RULE_INDEX_KEY = 'ruleIndex'
RULE_ID_KEY = 'ruleId'
PREREQUISITE_KEY_KEY = 'prerequisiteKey'
BIG_SEGMENTS_STATUS_KEY = 'bigSegmentsStatus'

private_constant :VARIATION_INDEX_KEY, :IN_EXPERIMENT_KEY, :RULE_INDEX_KEY, :RULE_ID_KEY,
:PREREQUISITE_KEY_KEY, :BIG_SEGMENTS_STATUS_KEY
private_constant :VARIATION_INDEX_KEY, :IN_EXPERIMENT_KEY, :OVERRIDE_AFFECTED_KEY, :RULE_INDEX_KEY,
:RULE_ID_KEY, :PREREQUISITE_KEY_KEY, :BIG_SEGMENTS_STATUS_KEY

#
# @param detail [LaunchDarkly::EvaluationDetail]
Expand Down Expand Up @@ -61,6 +62,7 @@ def to_resolution_details(detail)

metadata[VARIATION_INDEX_KEY] = variation_index unless variation_index.nil?
metadata[IN_EXPERIMENT_KEY] = true if reason.in_experiment
metadata[OVERRIDE_AFFECTED_KEY] = true if reason.override_affected
metadata[RULE_INDEX_KEY] = reason.rule_index unless reason.rule_index.nil?
metadata[RULE_ID_KEY] = reason.rule_id unless reason.rule_id.nil?
metadata[PREREQUISITE_KEY_KEY] = reason.prerequisite_key unless reason.prerequisite_key.nil?
Expand Down
31 changes: 31 additions & 0 deletions spec/impl/details_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,37 @@
expect(resolution_details.flag_metadata).not_to have_key('inExperiment')
end

it "includes override affected in the flag metadata for override-affected evaluations" do
reason = LaunchDarkly::EvaluationReason::rule_match(2, 'the-rule-id', false).with_override_affected(true)
detail = LaunchDarkly::EvaluationDetail.new(true, 1, reason)
resolution_details = details_converter.to_resolution_details(detail)

expect(resolution_details.flag_metadata).to include('overrideAffected' => true)
end

it "omits override affected from the flag metadata for evaluations not affected by an override" do
reason = LaunchDarkly::EvaluationReason::rule_match(2, 'the-rule-id', false).with_override_affected(false)
detail = LaunchDarkly::EvaluationDetail.new(true, 1, reason)
resolution_details = details_converter.to_resolution_details(detail)

expect(resolution_details.flag_metadata).not_to have_key('overrideAffected')
end

it "omits override affected from the flag metadata when the reason does not mark it" do
detail = LaunchDarkly::EvaluationDetail.new(true, 1, LaunchDarkly::EvaluationReason::fallthrough(false))
resolution_details = details_converter.to_resolution_details(detail)

expect(resolution_details.flag_metadata).not_to have_key('overrideAffected')
end

it "includes override affected in the flag metadata for error evaluations affected by an override" do
reason = LaunchDarkly::EvaluationReason::error(LaunchDarkly::EvaluationReason::ERROR_FLAG_NOT_FOUND).with_override_affected(true)
detail = LaunchDarkly::EvaluationDetail.new(true, nil, reason)
resolution_details = details_converter.to_resolution_details(detail)

expect(resolution_details.flag_metadata).to eq({'overrideAffected' => true})
end

it "includes the rule in the flag metadata for rule matches" do
detail = LaunchDarkly::EvaluationDetail.new(true, 1, LaunchDarkly::EvaluationReason::rule_match(2, 'the-rule-id', false))
resolution_details = details_converter.to_resolution_details(detail)
Expand Down
Loading