No results for ""
EXPAND ALL
  • Home
  • API docs

Flag evaluation reasons

Read time: 25 minutes
Last edited: Oct 21, 2024

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.

Newer versions of LaunchDarkly SDKs replace users with contexts

A context is a generalized way of referring to the people, services, machines, or other resources that encounter feature flags in your product. Contexts replace another data object in LaunchDarkly: "users." To learn more, read Contexts.

Creating contexts and evaluating flags based on them is supported in the latest major versions of most of our SDKs. For these SDKs, the code samples on this page include the two most recent versions.

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

  • Client-side SDKs
  • Server-side SDKs
  • Edge SDKs

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)

Expand .NET (client-side) code sample

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:

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

Android

Expand Android code sample

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:

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:

To learn more, read EvaluationReason.

C++ (client-side)

Expand C++ (client-side) code sample

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:

To learn more, read EvaluationDetail and BoolVariationDetail.

Electron

Expand Electron code sample

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:

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

Flutter

Expand Flutter code sample

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:

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:

To learn more, read LDEvaluationDetail.

iOS

Expand iOS code sample

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:

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

JavaScript

Expand JavaScript code sample

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:

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

Node.js (client-side)

Expand Node.js (client-side) code sample

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:

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

React Native

Expand React Native code sample

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:

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

Expand Roku code sample

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

Here is an example:

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)

Expand .NET (server-side) code sample

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:

To learn more, read EvaluationDetail, BoolVariationDetail.

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

To learn more, read EvaluationReason.

Apex

Expand Apex code sample

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

Here is an example:

C++ (server-side)

Expand C++ (server-side) code sample

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:

To learn more, read EvaluationDetail.

Erlang

Expand Erlang code sample

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:

Go

Expand Go code sample

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:

To learn more, read EvaluationDetail and BoolVariationDetail.

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

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

Expand Haskell code sample

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:

To learn more, read EvaluationDetail and boolVariationDetail.

Java

Expand Java code sample

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:

To learn more, read EvaluationDetail and boolVariationDetail.

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

To learn more, read EvaluationReason.

Lua

Expand Lua code sample

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

To learn more, read boolVariationDetail.

Node.js (server-side)

Expand Node.js (server-side) code sample

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:

To learn more, read LDEvaluationDetail and variationDetail.

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

To learn more, read LDEvaluationReason.

PHP

Expand PHP code sample

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:

To learn more, read EvaluationDetail and variationDetail.

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

To learn more, read EvaluationReason.

Python

Expand Python code sample

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:

To learn more, read EvaluationDetail and variation_detail.

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

To learn more, read EvaluationDetail.reason.

Ruby

Expand Ruby code sample

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:

To learn more, read EvaluationDetail and variation_detail.

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

To learn more, read EvaluationDetail.reason.

Rust

Expand Rust code sample

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:

To learn more, read variation_detail and bool_variation_detail.

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

To learn more, read Reason.

Edge SDKs

This feature is available for all of our edge SDKs:

Akamai

Expand Akamai code sample

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:

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

Expand Cloudflare code sample

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:

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

Expand Vercel code sample

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:

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.