Flag evaluation reasons

Overview

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 flag variations" on the details page for a context.

The "Expected flag 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 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:

1var config = Configuration
2 .Builder("mobile-key-123abc", ConfigurationBuilder.AutoEnvAttributes.Enabled)
3 .EvaluationReasons(true)
4 .Build();
5LdClient client = LdClient.Init(config, context);
6
7EvaluationDetail<bool> detail =
8 client.BoolVariationDetail("bool-flag-key-123abc", false);
9 // or StringVariationDetail for a string-valued flag, and so on.
10
11bool value = detail.Value;
12int? index = detail.VariationIndex;
13EvaluationReason 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:

1LDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled)
2 .mobileKey("mobile-key-123abc")
3 .evaluationReasons(true)
4 .build();
5LDClient client = LDClient.init(this.getApplication(), ldConfig, context, secondsToBlock);
6
7EvaluationDetail<Boolean> detail =
8 client.boolVariationDetail("flag-key-123abc", false);
9 // or stringVariationDetail for a string-valued flag, etc.
10
11boolean value = detail.getValue();
12Integer index = detail.getVariationIndex();
13EvaluationReason 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
1void printReason(EvaluationReason reason) {
2 switch (reason.getKind()) {
3 case OFF:
4 Timber.d("it's off");
5 break;
6 case FALLTHROUGH:
7 Timber.d("fell through");
8 break;
9 case TARGET_MATCH:
10 Timber.d("targeted");
11 break;
12 case RULE_MATCH:
13 EvaluationReason.RuleMatch rm =
14 (EvaluationReason.RuleMatch)reason;
15 Timber.d("matched rule %d/%s",
16 rm.getRuleIndex(),
17 rm.getRuleId());
18 break;
19 case PREREQUISITE_FAILED:
20 EvaluationReason.PrerequisiteFailed pf =
21 (EvaluationReason.PrerequisiteFailed)reason;
22 Timber.d("prereq failed: %s", pf.getPrerequisiteKey());
23 break;
24 case ERROR:
25 EvaluationReason.Error e = (EvaluationReason.Error)reason;
26 Timber.d("error: %s", e.getErrorKind());
27 }
28 // or, if all you want is a simple descriptive string:
29 Timber.d(reason.toString());
30}

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:

1auto detail = client.BoolVariationDetail("flag-key-123abc", false);
2if (detail.Value()) {
3 std::cout << "Value was true!" << std::endl;
4} else {
5 // it was false, let's find out why.
6 if (auto reason = detail.Reason()) {
7 // reason might not be present, so we have to check
8 std::cout << "Value was false because of " << reason << std::endl;
9 } else {
10 std::cout << "No reason provided to explain why flag was false!" << std::endl;
11 }
12}

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:

1const { value, variationIndex, reason } = client.variationDetail('flag-key-123abc', 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:

1final config = LDConfig(
2 CredentialSource.fromEnvironment,
3 AutoEnvAttributes.enabled,
4 dataSourceConfig: DataSourceConfig(
5 evaluationReasons: true
6 ),
7);
8
9// initialize client and context
10
11LDEvaluationDetail<bool> detail =
12 client.boolVariationDetail('flag-key-123abc', false);
13 // or stringVariationDetail for a string-valued flag, and so on.
14
15bool value = detail.value;
16int index = detail.variationIndex;
17LDEvaluationReason 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
1void printReason(LDEvaluationReason reason) {
2 switch (reason.kind) {
3 case LDKind.OFF:
4 print("it's off");
5 break;
6 case LDKind.FALLTHROUGH:
7 print('fell through');
8 break;
9 case LDKind.TARGET_MATCH:
10 print('targeted');
11 break;
12 case LDKind.RULE_MATCH:
13 print('matched rule: ${reason.ruleIndex} ${reason.ruleId}');
14 break;
15 case LDKind.PREREQUISITE_FAILED:
16 print('prereq failed: ${reason.prerequisiteKey}');
17 break;
18 case LDKind.ERROR:
19 print('error: ${reason.errorKind}');
20 break;
21 default: // LDKind.UNKNOWN
22 print('unknown service kind');
23 }
24}

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:

1ldConfig.evaluationReasons = true
2LDClient.start(config: ldConfig, context: context)
3
4let detail = client.boolVariationDetail(forKey: "flag-key-123abc", defaultValue: false);
5
6let value: Bool = detail.value
7let variationIndex: Int? = detail.variationIndex
8let 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.

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:

1const options = { evaluationReasons: true };
2const client = LDClient.initialize('client-side-id-123abc', context, options);
3
4const detail = client.variationDetail('flag-key-123abc', false);
5
6const value = detail.value;
7const index = detail.variationIndex;
8const reason = detail.reason;

To learn more about the variationDetail methods, read LDEvaluationDetail and variationDetail. 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
1const options = { evaluationReasons: true };
2const client = LDClient.initialize('client-side-id-123abc', user, options);
3
4const detail = client.variationDetail('flag-key-123abc', false);
5
6const value = detail.value;
7const index = detail.variationIndex;
8const 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:

1const { reason, value, variationIndex } = useBoolVariationDetail('flag-key-123abc', 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
1config.setUseEvaluationReasons(true)
2
3details = launchDarkly.intVariationDetail("flag-key-123abc", 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.

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:

1EvaluationDetail<bool> detail =
2 client.BoolVariationDetail("flag-key-123abc", myContext, false);
3 // or StringVariationDetail for a string-valued flag, etc.
4
5bool value = detail.Value;
6int? index = detail.VariationIndex;
7EvaluationReason reason = detail.Reason;

To learn more, read EvaluationDetail, BoolVariationDetail.

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

C#
1void PrintReason(EvaluationReason reason)
2{
3 switch (reason.Kind)
4 {
5 case EvaluationReasonKind.OFF:
6 Console.WriteLine("it's off");
7 break;
8 case EvaluationReasonKind.FALLTHROUGH:
9 Console.WriteLine("fell through");
10 break;
11 case EvaluationReasonKind.TARGET_MATCH:
12 Console.WriteLine("targeted");
13 break;
14 case EvaluationReasonKind.RULE_MATCH:
15 var rm = reason as EvaluationReason.RuleMatch;
16 Console.WriteLine("matched rule " + rm.RuleIndex + "/" + rm.RuleID);
17 break;
18 case EvaluationReasonKind.PREREQUISITE_FAILED:
19 var pf = reason as EvaluationReason.PrerequisiteFailed;
20 Console.WriteLine("prereq failed: " + pf.PrerequisiteKey);
21 break;
22 case EvaluationReasonKind.ERROR:
23 var e = reason as EvaluationReason.Error;
24 Console.WriteLine("error: " + e.ErrorKind);
25 break;
26 }
27 // or, if all you want is a simple descriptive string:
28 System.out.println(reason.ToString());
29}

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
1LDClient.EvaluationDetail details = new LDClient.EvaluationDetail();
2
3Boolean value = client.boolVariation(user, 'your.feature.key', false, details);
4
5/* inspect details here */
6if (details.getReason().getKind() == EvaluationReason.Kind.OFF) {
7 /* ... */
8}

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:

1auto detail = client.BoolVariationDetail(context, "flag-key-123abc", false);
2if (detail.Value()) {
3 std::cout << "Value was true!" << std::endl;
4} else {
5 // it was false, let's find out why
6 if (auto reason = detail.Reason()) {
7 // reason might not be present, so we have to check
8 std::cout << "Value was false because of " << reason << std::endl;
9 } else {
10 std::cout << "No reason provided to explain why flag was false!" << std::endl;
11 }
12}

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:

Flag = ldclient:variation_detail(<<"flag-key-123abc">>, #{key => <<"context-key-123abc">>}, false)

Go

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 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:

1value, detail, err := client.BoolVariationDetail("flag-key-123abc", context, false)
2// or StringVariationDetail for a string-valued flag, etc.
3
4index := detail.VariationIndex
5reason := detail.Reason

To learn more, read EvaluationDetail and BoolVariationDetail.

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

1import (
2 "github.com/launchdarkly/go-sdk-common/v3/ldreason"
3)
4
5func PrintReason(reason ldreason.EvaluationReason) {
6 switch reason.GetKind() {
7 case ldreason.EvalReasonOff:
8 fmt.Println("it's off")
9 case ldreason.EvalReasonFallthrough:
10 fmt.Println("fell through")
11 case ldreason.EvalReasonTargetMatch:
12 fmt.Println("targeted")
13 case ldreason.EvalReasonRuleMatch:
14 fmt.Printf("matched rule %d/%s\n", r.GetRuleIndex(), r.GetRuleID())
15 case ldreason.EvalReasonPrerequisiteFailed:
16 fmt.Printf("prereq failed: %s\n", r.GetPrerequisiteKey())
17 case ldreason.EvalReasonError:
18 fmt.Printf("error: %s\n", r.GetErrorKind())
19 }
20 // or, if all you want is a simple descriptive string:
21 fmt.Println(reason)
22}

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:

1details :: IO (EvaluationDetail Bool)
2details = boolVariationDetail client "flag-key-123abc" 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:

1import com.launchdarkly.sdk.*;
2
3EvaluationDetail<Boolean> detail =
4 client.boolVariationDetail("flag-key-123abc", context, false);
5 // or stringVariationDetail for a string-valued flag, and so on.
6
7boolean value = detail.getValue();
8int index = detail.getVariationIndex(); // will be < 0 if evaluation failed
9EvaluationReason 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
1void printReason(EvaluationReason reason) {
2 switch (reason.getKind()) {
3 case OFF:
4 System.out.println("it's off");
5 break;
6 case FALLTHROUGH:
7 System.out.println("fell through");
8 break;
9 case TARGET_MATCH:
10 System.out.println("targeted");
11 break;
12 case RULE_MATCH:
13 EvaluationReason.RuleMatch rm = (EvaluationReason.RuleMatch)reason;
14 System.out.println("matched rule " + rm.getRuleIndex()
15 + "/" + rm.getRuleId());
16 break;
17 case PREREQUISITE_FAILED:
18 EvaluationReason.PrerequisiteFailed pf =
19 (EvaluationReason.PrerequisiteFailed)reason;
20 System.out.println("prereq failed: " + pf.getPrerequisiteKey());
21 break;
22 case ERROR:
23 EvaluationReason.Error e = (EvaluationReason.Error)reason;
24 System.out.println("error: " + e.getErrorKind());
25 }
26 // or, if all you want is a simple descriptive string:
27 System.out.println(reason.toString());
28}

To learn more, read EvaluationReason.

Lua

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

1local details = client:boolVariationDetail(client, context, "flag-key-123abc", false);
2
3-- inspect details here
4if details.reason == "FLAG_NOT_FOUND" then
5end

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:

1var detail = client.variationDetail('flag-key-123abc', context, false);
2
3var value = detail.value;
4var index = detail.variationIndex;
5var 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
1function printReason(reason) {
2 switch(reason.kind) {
3 case "OFF":
4 console.log("it's off");
5 break;
6 case "FALLTHROUGH":
7 console.log("fell through");
8 break;
9 case "TARGET_MATCH":
10 console.log("targeted");
11 break;
12 case "RULE_MATCH":
13 console.log("matched rule " + reason.ruleIndex + ", " + reason.ruleId);
14 break;
15 case "PREREQUISITE_FAILED":
16 console.log("prereq failed: " + reason.prerequisiteKey);
17 break;
18 case "ERROR":
19 console.log("error: " + reason.errorKind);
20 break;
21 }
22}

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:

1$detail = $client->variationDetail("flag-key-123abc", $myContext, false);
2
3$value = $detail->getValue();
4$index = $detail->getVariationIndex();
5$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 SDK v5.0 and earlier
1function printReason($reason) {
2 switch ($reason->getKind()) {
3 case EvaluationReason::OFF:
4 echo("it's off");
5 break;
6 case EvaluationReason::FALLTHROUGH:
7 echo("fell through");
8 break;
9 case EvaluationReason::TARGET_MATCH:
10 echo("targeted");
11 break;
12 case EvaluationReason::RULE_MATCH:
13 echo("matched rule " . $reason->getRuleIndex() .
14 "/" . $reason->getRuleId());
15 break;
16 case EvaluationReason::PREREQUISITE_FAILED:
17 echo("prereq failed: " . $reason->getPrerequisiteKey());
18 break;
19 case EvaluationReason::ERROR:
20 echo("error: " . $reason->getErrorKind());
21 break;
22 }
23 // or, if all you want is a simple descriptive string:
24 echo $reason;
25}

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:

1detail = client.variation_detail("flag-key-123abc", my_context, False)
2value = detail.value
3index = detail.variation_index
4reason = 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
1def print_reason(reason):
2 kind = reason["kind"]
3 if kind == "OFF":
4 print "it's off"
5 elif kind == "FALLTHROUGH":
6 print "fell through"
7 elif kind == "TARGET_MATCH":
8 print "targeted"
9 elif kind == "RULE_MATCH":
10 print "matched rule %d/%s" % (reason["ruleIndex"], reason["ruleId"])
11 elif kind == "PREREQUISITE_FAILED":
12 print "prereq failed: %s" % reason["prerequisiteKey"]
13 elif kind == "ERROR":
14 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:

1detail = client.variation_detail("flag-key-123abc", my_context, false)
2value = detail.value
3index = detail.variation_index
4reason = 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
1def print_reason(reason)
2 case reason[:kind]
3 when "OFF"
4 puts "it's off"
5 when "FALLTHROUGH"
6 puts "fell through"
7 when "TARGET_MATCH"
8 puts "targeted"
9 when "RULE_MATCH"
10 puts "matched rule #{reason[:ruleIndex]}/#{reason[:ruleId]}"
11 when "PREREQUISITE_FAILED"
12 puts "prereq failed: #{reason[:prerequisiteKey]}"
13 when "ERROR"
14 puts "error: #{reason[:errorKind]}"
15 end
16end

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:

1let detail = client.bool_variation_detail(&context, "flag-key-123abc", false);
2
3let value = detail.value;
4let index = detail.variation_index;
5let 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
1fn print_reason(reason: Reason) {
2 match reason {
3 Reason::Off => println!("it's off"),
4 Reason::Fallthrough { .. } => println!("fell through"),
5 Reason::TargetMatch => println!("targeted"),
6 Reason::RuleMatch {
7 rule_index,
8 rule_id,
9 ..
10 } => println!("matched rule {}/{}", rule_index, rule_id),
11 Reason::PrerequisiteFailed { prerequisite_key } => {
12 println!("prereq failed: {}", prerequisite_key)
13 }
14 Reason::Error { error } => println!("error: {:?}", error),
15 };
16}

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
1const { 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.

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
1const { 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.

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
1const { 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.

Built with