Flag variation evaluation details

This topic explains how to use the flag evaluation reason feature to get more information about the flag variations LaunchDarkly serves to contexts or users.

You can find the evaluation reason for a specific context on its details page:

The "Expected variations" on the details page for a context.

The "Expected variations" on the details page for a context.

To learn more about how LaunchDarkly determines why a context or user receives a given flag variation, read Evaluation reasons in the SDK Concepts section. For additional guidance, read How to use the SDK’s “evaluation reasons” feature to troubleshoot flag evaluation.

Details about each SDK’s configuration are available in the SDK-specific sections below.

Client-side SDKs

An evaluation reason configuration option is required

In client-side SDKs, you must enable an evaluation reason configuration option for this feature to work. The code samples below include this option. To learn more about configuration options, read SDK configuration.

This feature is available in the following client-side SDKs:

.NET (client-side)

The VariationDetail methods, such as BoolVariationDetail, work the same as Variation, but also provide additional “reason” information about how a flag value was calculated. For example, you can find out if the context was individually targeted for the flag or was matched by one of the flag’s rules. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

.NET SDK v4.0+ (C#)
var config = Configuration
.Builder("example-mobile-key", ConfigurationBuilder.AutoEnvAttributes.Enabled)
.EvaluationReasons(true)
.Build();
LdClient client = LdClient.Init(config, context, TimeSpan.FromSeconds(10));
EvaluationDetail<bool> detail =
client.BoolVariationDetail("example-bool-flag-key", false);
// or StringVariationDetail for a string-valued flag, and so on.
bool value = detail.Value;
int? index = detail.VariationIndex;
EvaluationReason reason = detail.Reason;

To learn more about the VariationDetail methods, read EvaluationDetail and BoolVariationDetail. To learn more about the configuration option, read EvaluationReasons.

Android

The variationDetail methods, such as boolVariationDetail, work the same as variation. They also provide additional “reason” information about how a flag value was calculated, such as if the context matched a specific rule. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

Android SDK v5.x (Java)
LDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled)
.mobileKey("example-mobile-key")
.evaluationReasons(true)
.build();
LDClient client = LDClient.init(this.getApplication(), ldConfig, context, secondsToBlock);
EvaluationDetail<Boolean> detail =
client.boolVariationDetail("example-flag-key", false);
// or stringVariationDetail for a string-valued flag, etc.
boolean value = detail.getValue();
Integer index = detail.getVariationIndex();
EvaluationReason reason = detail.getReason();

To learn more about the variationDetail methods, read EvaluationDetail and getVariationIndex. To learn more about the configuration option, read evaluationReasons.

Here is an example of how to access the details of a reason object:

Java
void printReason(EvaluationReason reason) {
switch (reason.getKind()) {
case OFF:
Timber.d("it's off");
break;
case FALLTHROUGH:
Timber.d("fell through");
break;
case TARGET_MATCH:
Timber.d("targeted");
break;
case RULE_MATCH:
Timber.d("matched rule %d/%s",
reason.getRuleIndex(),
reason.getRuleId());
break;
case PREREQUISITE_FAILED:
Timber.d("prereq failed: %s", reason.getPrerequisiteKey());
break;
case ERROR:
Timber.d("error: %s", reason.getErrorKind());
}
// or, if all you want is a simple descriptive string:
Timber.d(reason.toString());
}

To learn more, read EvaluationReason.

C++ (client-side)

You can request and then programmatically inspect the reason for a particular feature flag evaluation.

The detail.Reason() response is described in Evaluation reasons.

Here is an example:

auto detail = client.BoolVariationDetail("example-flag-key", false);
if (detail.Value()) {
std::cout << "Value was true!" << std::endl;
} else {
// it was false, let's find out why.
if (auto reason = detail.Reason(); reason.has_value()) {
// reason might not be present, so we have to check
std::cout << "Value was false because of " << reason.value() << std::endl;
} else {
std::cout << "No reason provided to explain why flag was false!" << std::endl;
}
}

To learn more, read EvaluationDetail and BoolVariationDetail.

Electron

The variationDetail methods work the same as variation. They also provide additional “reason” information about how a flag value was calculated. For example, you can find out if the context was individually targeted for the flag or was matched by one of the flag’s rules. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

const { value, variationIndex, reason } = client.variationDetail('example-flag-key', false);

To learn more about the variationDetail methods, read LDEvaluationDetail and variationDetail. To learn more about the configuration option, read LDEvaluationReason.

Flutter

The variationDetail methods, such as boolVariationDetail, work the same as variation. They also provide additional “reason” information about how a flag value was calculated. For example, you can find out if the context was individually targeted for the flag or was matched by one of the flag’s rules. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

To enable this functionality, set the evaluationReasons configuration option to true when you initialize the client.

Here is an example:

Flutter SDK v4
final config = LDConfig(
CredentialSource.fromEnvironment(),
AutoEnvAttributes.enabled,
dataSourceConfig: DataSourceConfig(
evaluationReasons: true
),
);
// initialize client and context
LDEvaluationDetail<bool> detail =
client.boolVariationDetail('example-flag-key', false);
// or stringVariationDetail for a string-valued flag, and so on.
bool value = detail.value;
int? index = detail.variationIndex;
LDEvaluationReason? reason = detail.reason;

To learn more about the variationDetail methods, read LDEvaluationDetail and boolVariationDetail. To learn more about the configuration option, read evaluationReasons.

Here is an example of how to access the details of a reason object:

Dart
void printReason(LDEvaluationReason reason) {
switch (reason.kind) {
case LDKind.off:
print("it's off");
break;
case LDKind.fallthrough:
print('fell through');
break;
case LDKind.targetMatch:
print('targeted');
break;
case LDKind.ruleMatch:
print('matched rule: ${reason.ruleIndex} ${reason.ruleId}');
break;
case LDKind.prerequisiteFailed:
print('prereq failed: ${reason.prerequisiteKey}');
break;
case LDKind.error:
print('error: ${reason.errorKind}');
break;
}
}

To learn more, read LDEvaluationDetail.

iOS

The variationDetail methods, such as boolVariationDetail, work the same as the variation methods. They also provide additional “reason” information about how a flag value was calculated, such as if the user matched a specific rule. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

ldConfig.evaluationReasons = true
LDClient.start(config: ldConfig, context: context)
let detail = client.boolVariationDetail(forKey: "example-flag-key", defaultValue: false);
let value: Bool = detail.value
let variationIndex: Int? = detail.variationIndex
let reason: [String: LDValue]? = detail.reason

To learn more about the variationDetail methods, read LDEvaluationDetail and boolVariationDetail. To learn more about the configuration option, read LDConfig.

JavaScript

The variationDetail method lets you evaluate a feature flag with the same parameters you would for variation. With variationDetail, you receive more information about how the value was calculated. In v4.x of the JavaScript SDK you can also use typed methods, for example, boolVariationDetail for boolean feature flags.

The variation detail returns in an object containing both the result value and a “reason” object which tells you more information about the flag evaluation. For example, you can find out if the context was individually targeted for the flag or was matched by one of the flag’s rules. It also indicates if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

const options = { withReasons: true };
const client = createClient('example-client-side-id', context, options);
client.start();
await client.waitForInitialization({ timeout: 5 });
const detail = client.boolVariationDetail('example-flag-key', false);
// or stringVariationDetail for a string-valued flag, and so on.
const value = detail.value;
const index = detail.variationIndex;
const reason = detail.reason;

To learn more about the *variationDetail methods, read LDEvaluationDetail. To learn more about the configuration option, read evaluationReasons.

Node.js (client-side)

The variationDetail method lets you evaluate a feature flag with the same parameters you would for variation. With variationDetail, you receive more information about how the value was calculated.

The variation detail returns in an object that contains both the result value and a “reason” object which tells you more information about the flag evaluation. For example, you can find out if the user was individually targeted for the flag or was matched by one of the flag’s rules. It also indicates if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

JavaScript
const options = { evaluationReasons: true };
const client = LDClient.initialize('example-client-side-id', user, options);
const detail = client.variationDetail('example-flag-key', false);
const value = detail.value;
const index = detail.variationIndex;
const reason = detail.reason;

To learn more about the variationDetail method, read LDEvaluationDetail and variationDetail. To learn more about the configuration option, read evaluationReasons.

React Native

The variationDetail methods work the same way as the variation methods, and also provide additional information about how a flag value was calculated. For example, you can find out if the context was individually targeted for the flag or was matched by one of the flag’s rules. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export. To view this reason information, set the withReasons configuration option to true.

In React Native, there is a variation detail method for each type, such as boolVariationDetail or stringVariationDetail. In the React Native SDK version 10, there is also a hook for each type, such as useBoolVariationDetail or useStringVariationDetail.

Here is an example:

const { reason, value, variationIndex } = useBoolVariationDetail('example-flag-key', false);

To learn more about the variationDetail methods, read LDEvaluationDetail, useBoolVariationDetail and boolVariationDetail.

To learn more about the withReasons configuration option, read LDOptions.

The SDK also includes an untyped method to determine the variation of a feature flag and provide information about how the flag value was calculated. To learn more, read variationDetail. We recommend using the strongly typed variation methods, such as boolVariationDetail, which perform type checks and handle type errors.

Roku

For each variation type there is also an associated version that returns the reason a particular value was returned.

Here is an example:

BrightScript
config.setUseEvaluationReasons(true)
details = launchDarkly.intVariationDetail("example-flag-key", 123)

These variation methods return an object containing the keys value, reason, and variationIndex. The value field is the result of the evaluation. The reason field is an object that explains why the result happened, for example details about a rule match. The reason object will always contain a kind field. Lastly the variationIndex field contains the ID of the particular value returned. This field may be null.

Vue

The Vue SDK provides a variation detail composable for each flag type: useBoolVariationDetail, useStringVariationDetail, useNumberVariationDetail, and useJsonVariationDetail. Each one returns a readonly ref for an evaluation detail object containing the flag value, the variation index, and the evaluation reason.

The SDK populates the reason only when you set withReasons to true in ldOptions. Before the client is ready, the detail contains the default value and a CLIENT_NOT_READY error reason.

First, enable withReasons when you install the plugin or create the provider:

Vue SDK v3.0
import { createApp } from 'vue'
import { LDVuePlugin } from '@launchdarkly/vue-client-sdk'
import App from './App.vue'
createApp(App)
.use(LDVuePlugin, {
clientSideID: 'example-client-side-id',
context: { kind: 'user', key: 'example-context-key' },
ldOptions: { withReasons: true }
})
.mount('#app')

Then, read the detail in your component:

Vue SDK v3.0
<script setup lang="ts">
import { useBoolVariationDetail } from '@launchdarkly/vue-client-sdk'
const flagDetail = useBoolVariationDetail('example-flag-key', false)
// or useStringVariationDetail for a string-valued flag, and so on.
// In script, read the detail through the ref's own `.value`:
const value = flagDetail.value.value
const index = flagDetail.value.variationIndex
const reason = flagDetail.value.reason
</script>
<template>
<!-- In templates, Vue unwraps the ref for you -->
<div>The flag value is {{ flagDetail.value }}, because {{ flagDetail.reason?.kind }}.</div>
</template>

Server-side SDKs

Unlike client-side SDKs, you do not need to enable an evaluation reason configuration option in server-side SDKs for this feature to work.

This feature is available in the following server-side SDKs:

.NET (server-side)

The VariationDetail methods, such as BoolVariationDetail, work the same as the Variation methods, but also provide additional “reason” information about how a flag value was calculated. For example, you can find out if the context was individually targeted for the flag or was matched by one of the flag’s rules. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

.NET SDK v7.0+ (C#)
EvaluationDetail<bool> detail =
client.BoolVariationDetail("example-flag-key", myContext, false);
// or StringVariationDetail for a string-valued flag, etc.
bool value = detail.Value;
int? index = detail.VariationIndex;
EvaluationReason reason = detail.Reason;

To learn more, read EvaluationDetail, BoolVariationDetail.

Here is an example of how to access the details of a reason object:

C#
void PrintReason(EvaluationReason reason)
{
switch (reason.Kind)
{
case EvaluationReasonKind.Off:
Console.WriteLine("it's off");
break;
case EvaluationReasonKind.Fallthrough:
Console.WriteLine("fell through");
break;
case EvaluationReasonKind.TargetMatch:
Console.WriteLine("targeted");
break;
case EvaluationReasonKind.RuleMatch:
Console.WriteLine("matched rule " + reason.RuleIndex + "/" + reason.RuleId);
break;
case EvaluationReasonKind.PrerequisiteFailed:
Console.WriteLine("prereq failed: " + reason.PrerequisiteKey);
break;
case EvaluationReasonKind.Error:
Console.WriteLine("error: " + reason.ErrorKind);
break;
}
// or, if all you want is a simple descriptive string:
Console.WriteLine(reason.ToString());
}

To learn more, read EvaluationReason.

Apex

By passing an LDClient.EvaluationDetail object to a variation call you can programmatically inspect the reason for a particular evaluation.

Here is an example:

Apex
LDClient.EvaluationDetail details = new LDClient.EvaluationDetail();
Boolean value = client.boolVariation(user, 'your.feature.key', false, details);
/* inspect details here */
if (details.getReason().getKind() == EvaluationReason.Kind.OFF) {
/* ... */
}

C++ (server-side)

You can request and then programmatically inspect the reason for a particular feature flag evaluation.

The detail.Reason() response is described in Evaluation reasons.

Here is an example:

auto detail = client.BoolVariationDetail(context, "example-flag-key", false);
if (detail.Value()) {
std::cout << "Value was true!" << std::endl;
} else {
// it was false, let's find out why
if (auto reason = detail.Reason(); reason.has_value()) {
// reason might not be present, so we have to check
std::cout << "Value was false because of " << reason.value() << std::endl;
} else {
std::cout << "No reason provided to explain why flag was false!" << std::endl;
}
}

To learn more, read EvaluationDetail.

Erlang

The variation_detail function is similar to the variation function, but also returns an explanation of the evaluation that you can inspect programmatically.

Here is an example:

Erlang SDK v2.0+
Flag = ldclient:variation_detail(<<"example-flag-key">>, #{key => <<"example-context-key">>}, false)

Go

The VariationDetail methods, such as BoolVariationDetail, work the same way as Variation, but also provide additional “reason” information about how a flag value was calculated. For example, you can find out if the context was individually targeted by the flag or was matched by one of the flag’s rules. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

value, detail, err := scopedClient.BoolVariationDetail("example-flag-key", false)
// or StringVariationDetail for a string-valued flag, etc.
// LDScopedClient is in beta and may change without notice.
index := detail.VariationIndex
reason := detail.Reason

To learn more, read EvaluationDetail and BoolVariationDetail.

Here is an example of how to access the details of a reason object:

Go SDK v6+
import (
"github.com/launchdarkly/go-sdk-common/v3/ldreason"
)
func PrintReason(reason ldreason.EvaluationReason) {
switch reason.GetKind() {
case ldreason.EvalReasonOff:
fmt.Println("it's off")
case ldreason.EvalReasonFallthrough:
fmt.Println("fell through")
case ldreason.EvalReasonTargetMatch:
fmt.Println("targeted")
case ldreason.EvalReasonRuleMatch:
fmt.Printf("matched rule %d/%s\n", reason.GetRuleIndex(), reason.GetRuleID())
case ldreason.EvalReasonPrerequisiteFailed:
fmt.Printf("prereq failed: %s\n", reason.GetPrerequisiteKey())
case ldreason.EvalReasonError:
fmt.Printf("error: %s\n", reason.GetErrorKind())
}
// or, if all you want is a simple descriptive string:
fmt.Println(reason)
}

To learn more, read EvaluationReason.

If you are using OpenTelemetry, then instead of using the VariationDetail method for each type, you must use the VariationDetailCtx method for each type. For example, use BoolVariationDetailCtx rather than BoolVariationDetail. The methods are the same except that the VariationDetailCtx methods also require a Go context parameter. This Go context is used in the hook implementation that provides OpenTelemetry support. To learn more, read OpenTelemetry.

Haskell

The variationDetail functions are similar to the variation functions, but they also return an explanation of the evaluation that is programmatically inspectable.

Here is an example:

Haskell SDK v4.0
details :: IO (EvaluationDetail Bool)
details = boolVariationDetail client "example-flag-key" context False

To learn more, read EvaluationDetail and boolVariationDetail.

Java

The variationDetail methods, such as boolVariationDetail, work the same as variation, but also provide additional “reason” information about how a flag value was calculated. For example, you can find out if the context was individually targeted for the flag or was matched by one of the flag’s rules. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

Java SDK v6.0+
import com.launchdarkly.sdk.*;
EvaluationDetail<Boolean> detail =
client.boolVariationDetail("example-flag-key", context, false);
// or stringVariationDetail for a string-valued flag, and so on.
boolean value = detail.getValue();
int index = detail.getVariationIndex(); // will be < 0 if evaluation failed
EvaluationReason reason = detail.getReason();

To learn more, read EvaluationDetail and boolVariationDetail.

Here is an example of how to access the details of a reason object:

Java
void printReason(EvaluationReason reason) {
switch (reason.getKind()) {
case OFF:
System.out.println("it's off");
break;
case FALLTHROUGH:
System.out.println("fell through");
break;
case TARGET_MATCH:
System.out.println("targeted");
break;
case RULE_MATCH:
System.out.println("matched rule " + reason.getRuleIndex()
+ "/" + reason.getRuleId());
break;
case PREREQUISITE_FAILED:
System.out.println("prereq failed: " + reason.getPrerequisiteKey());
break;
case ERROR:
System.out.println("error: " + reason.getErrorKind());
}
// or, if all you want is a simple descriptive string:
System.out.println(reason.toString());
}

To learn more, read EvaluationReason.

Lua

By using the *VariationDetail family of variation calls you can programmatically inspect the reason for a particular evaluation:

Lua SDK v2
local details = client:boolVariationDetail(context, "example-flag-key", false);
-- inspect details here
if details.reason.kind == "ERROR" and details.reason.errorKind == "FLAG_NOT_FOUND" then
end

To learn more, read boolVariationDetail.

Node.js (server-side)

The variationDetail method lets you evaluate a feature flag (using the same parameters as you would for variation) and receive more information about how the value was calculated.

The variation detail is returned in an object that contains both the result value and a “reason” object which will tell you, for instance, if the context was individually targeted for the flag or was matched by one of the flag’s rules. It will also indicate if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

var detail = client.variationDetail('example-flag-key', context, false);
var value = detail.value;
var index = detail.variationIndex;
var reason = detail.reason;

To learn more, read LDEvaluationDetail and variationDetail.

Here is an example of how to access the details of a reason object:

JavaScript
function printReason(reason) {
switch(reason.kind) {
case "OFF":
console.log("it's off");
break;
case "FALLTHROUGH":
console.log("fell through");
break;
case "TARGET_MATCH":
console.log("targeted");
break;
case "RULE_MATCH":
console.log("matched rule " + reason.ruleIndex + ", " + reason.ruleId);
break;
case "PREREQUISITE_FAILED":
console.log("prereq failed: " + reason.prerequisiteKey);
break;
case "ERROR":
console.log("error: " + reason.errorKind);
break;
}
}

To learn more, read LDEvaluationReason.

PHP

The variationDetail method lets you evaluate a feature flag (using the same parameters as you would for variation) and receive more information about how the value was calculated.

The variation detail is returned in an object that contains both the result value and a “reason” object which will tell you, for example, if the context was individually targeted for the flag or was matched by one of the flag’s rules. It will also indicate if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

PHP SDK v5.0+
$detail = $client->variationDetail("example-flag-key", $myContext, false);
$value = $detail->getValue();
$index = $detail->getVariationIndex();
$reason = $detail->getReason();

To learn more, read EvaluationDetail and variationDetail.

Here is an example of how to access the details of a reason object:

PHP
function printReason($reason) {
switch ($reason->getKind()) {
case EvaluationReason::OFF:
echo("it's off");
break;
case EvaluationReason::FALLTHROUGH:
echo("fell through");
break;
case EvaluationReason::TARGET_MATCH:
echo("targeted");
break;
case EvaluationReason::RULE_MATCH:
echo("matched rule " . $reason->getRuleIndex() .
"/" . $reason->getRuleId());
break;
case EvaluationReason::PREREQUISITE_FAILED:
echo("prereq failed: " . $reason->getPrerequisiteKey());
break;
case EvaluationReason::ERROR:
echo("error: " . $reason->getErrorKind());
break;
}
// or, if all you want is a simple descriptive string:
echo $reason;
}

To learn more, read EvaluationReason.

Python

The variation_detail method lets you evaluate a feature flag with the same parameters as you would for variation. You can use this method to receive more information about how the value was calculated.

The variation detail is returned in an object that contains both the result value and a “reason” object which will tell you, for instance, if the context was individually targeted for the flag or was matched by one of the flag’s rules. It will also indicate if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

Python SDK v8.0+
detail = client.variation_detail("example-flag-key", my_context, False)
value = detail.value
index = detail.variation_index
reason = detail.reason

To learn more, read EvaluationDetail and variation_detail.

Here is an example of how to access the details of a reason object:

Python
def print_reason(reason):
kind = reason["kind"]
if kind == "OFF":
print("it's off")
elif kind == "FALLTHROUGH":
print("fell through")
elif kind == "TARGET_MATCH":
print("targeted")
elif kind == "RULE_MATCH":
print("matched rule %d/%s" % (reason["ruleIndex"], reason["ruleId"]))
elif kind == "PREREQUISITE_FAILED":
print("prereq failed: %s" % reason["prerequisiteKey"])
elif kind == "ERROR":
print("error: %s" % reason["errorKind"])

To learn more, read EvaluationDetail.reason.

Ruby

The variation_detail method lets you evaluate a feature flag (using the same parameters as you would for variation) and receive more information about how the value was calculated.

The variation detail is returned in an object that contains both the result value and a “reason” object which will tell you, for instance, if the context was individually targeted for the flag or was matched by one of the flag’s rules. It will also indicate if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

Ruby SDK v7.0+
detail = client.variation_detail("example-flag-key", my_context, false)
value = detail.value
index = detail.variation_index
reason = detail.reason

To learn more, read EvaluationDetail and variation_detail.

Here is an example of how to access the details of a reason object:

Ruby
def print_reason(reason)
case reason[:kind]
when "OFF"
puts "it's off"
when "FALLTHROUGH"
puts "fell through"
when "TARGET_MATCH"
puts "targeted"
when "RULE_MATCH"
puts "matched rule #{reason[:ruleIndex]}/#{reason[:ruleId]}"
when "PREREQUISITE_FAILED"
puts "prereq failed: #{reason[:prerequisiteKey]}"
when "ERROR"
puts "error: #{reason[:errorKind]}"
end
end

To learn more, read EvaluationDetail.reason.

Rust

The variation_detail methods (for example, bool_variation_detail) let you evaluate a feature flag, using the same parameters as you would for variation, and receive more information about how the flag value was calculated. For example, you can find out if the context was individually targeted for the flag or was matched by one of the flag’s rules. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

Rust SDK v1+
let detail = client.bool_variation_detail(&context, "example-flag-key", false);
let value = detail.value;
let index = detail.variation_index;
let reason = detail.reason;

To learn more, read variation_detail and bool_variation_detail.

Here is an example of how to access the details of a reason object:

Rust SDK v1+
fn print_reason(reason: Reason) {
match reason {
Reason::Off => println!("it's off"),
Reason::Fallthrough { .. } => println!("fell through"),
Reason::TargetMatch => println!("targeted"),
Reason::RuleMatch {
rule_index,
rule_id,
..
} => println!("matched rule {}/{}", rule_index, rule_id),
Reason::PrerequisiteFailed { prerequisite_key } => {
println!("prereq failed: {}", prerequisite_key)
}
Reason::Error { error } => println!("error: {:?}", error),
};
}

To learn more, read Reason.

Edge SDKs

This feature is available for all of our edge SDKs:

Akamai

The variationDetail method lets you evaluate a feature flag using the same parameters as you would for variation and receive more information about how the value was calculated.

The SDK returns the variation detail in an object that contains both the result value and a reason object. These tell you more information. For example, they can tell you if the flag individually targeted the context, or if the context matched one of the flag’s rules. It will also indicate if the flag returned the default value due to an error. You can examine the reason data programmatically.

Here is an example:

TypeScript
const { value, variationIndex, reason } = await client.variationDetail(flagKey, context, false);

To learn more, read variationDetail, LDEvaluationDetail and LDEvaluationReason.

The LDClient also provides typed variation methods for type-safe usage in TypeScript: boolVariationDetail, stringVariationDetail, numberVariationDetail, jsonVariationDetail.

Every time you evaluate a flag, the SDK fetches the flag data from the EdgeKV store. Your Akamai resource tier may limit how many of these queries you can make while a single worker handler is being executed. To learn more, read Understand resource limits and caching options.

Cloudflare

The variationDetail method lets you evaluate a feature flag using the same parameters as you would for variation and receive more information about how the value was calculated.

The SDK returns the variation detail in an object that contains both the result value and a “reason” object. These tell you, for instance, if the flag individually targeted the context or if the context matched one of the flag’s rules. It will also indicate if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

TypeScript
const { value, variationIndex, reason } = await client.variationDetail(flagKey, context, false);

To learn more, read variationDetail, LDEvaluationDetail and LDEvaluationReason.

The LDClient also provides typed variation methods for type-safe usage in TypeScript: boolVariationDetail, stringVariationDetail, numberVariationDetail, jsonVariationDetail.

Fastly

The variationDetail method lets you evaluate a feature flag using the same parameters as you would for variation and receive more information about how the value was calculated.

The SDK returns the variation detail in an object that contains both the result value and a “reason” object. These tell you more information. For example, they can tell you if the flag individually targeted the context, or if the context matched one of the flag’s rules. It will also indicate if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

TypeScript
const { value, variationIndex, reason } = await client.variationDetail('example-flag-key', context, false);

To learn more, read variationDetail and LDEvaluationReason.

The LDClient also provides typed variation methods for type-safe usage in TypeScript: boolVariationDetail, stringVariationDetail, numberVariationDetail, jsonVariationDetail.

Vercel

The variationDetail method lets you evaluate a feature flag using the same parameters as you would for variation and receive more information about how the value was calculated.

The SDK returns the variation detail in an object that contains both the result value and a “reason” object. These tell you more information. For example, they can tell you if the flag individually targeted the context, or if the context matched one of the flag’s rules. It will also indicate if the flag returned the default value due to an error. You can examine the “reason” data programmatically, or, if you capture detailed analytics events for flags, view it with Data Export.

Here is an example:

TypeScript
const { value, variationIndex, reason } = await client.variationDetail(flagKey, context, false);

To learn more, read variationDetail, LDEvaluationDetail and LDEvaluationReason.

The LDClient also provides typed variation methods for type-safe usage in TypeScript: boolVariationDetail, stringVariationDetail, numberVariationDetail, jsonVariationDetail.