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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.
//
using Microsoft.ApplicationInsights;
using System.Diagnostics;

namespace Microsoft.FeatureManagement.Telemetry.ApplicationInsights
{
Expand Down Expand Up @@ -30,15 +31,17 @@ public ValueTask PublishEvent(EvaluationEvent evaluationEvent, CancellationToken

FeatureDefinition featureDefinition = evaluationEvent.FeatureDefinition;

Dictionary<string, string> properties = new Dictionary<string, string>()
var properties = new Dictionary<string, string>()
{
{ "FeatureName", featureDefinition.Name },
{ "IsEnabled", evaluationEvent.IsEnabled.ToString() }
{ "Enabled", evaluationEvent.Enabled.ToString() }
};

if (evaluationEvent.Variant != null)
if (evaluationEvent.VariantAssignmentReason != VariantAssignmentReason.None)
{
properties["Variant"] = evaluationEvent.Variant.Name;
properties["Variant"] = evaluationEvent.Variant?.Name;

properties["VariantAssignmentReason"] = ToString(evaluationEvent.VariantAssignmentReason);
Copy link
Member

@jimmyca15 jimmyca15 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always send Variant if assignment reason is not None. Even if variant is null. So there shouldn't be a need for the if (evaluationEvent.Variant != null) check.

}

if (featureDefinition.TelemetryMetadata != null)
Expand Down Expand Up @@ -66,5 +69,26 @@ private void ValidateEvent(EvaluationEvent evaluationEvent)
throw new ArgumentNullException(nameof(evaluationEvent.FeatureDefinition));
}
}

private static string ToString(VariantAssignmentReason reason)
{
Debug.Assert(reason != VariantAssignmentReason.None);

const string DefaultWhenDisabled = "DefaultWhenDisabled";
const string DefaultWhenEnabled = "DefaultWhenEnabled";
const string User = "User";
const string Group = "Group";
const string Percentile = "Percentile";

return reason switch
{
VariantAssignmentReason.DefaultWhenDisabled => DefaultWhenDisabled,
VariantAssignmentReason.DefaultWhenEnabled => DefaultWhenEnabled,
VariantAssignmentReason.User => User,
VariantAssignmentReason.Group => Group,
VariantAssignmentReason.Percentile => Percentile,
_ => throw new ArgumentException("Invalid assignment reason.", nameof(reason))
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
245 changes: 122 additions & 123 deletions src/Microsoft.FeatureManagement/FeatureManager.cs

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions src/Microsoft.FeatureManagement/Telemetry/EvaluationEvent.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
using Microsoft.FeatureManagement.FeatureFilters;

namespace Microsoft.FeatureManagement.Telemetry
{
/// <summary>
Expand All @@ -18,11 +16,16 @@ public class EvaluationEvent
/// <summary>
/// The enabled state of the feature after evaluation.
/// </summary>
public bool IsEnabled { get; set; }
public bool Enabled { get; set; }

/// <summary>
/// The variant given after evaluation.
/// </summary>
public Variant Variant { get; set; }

/// <summary>
/// The reason why the variant was assigned.
/// </summary>
public VariantAssignmentReason VariantAssignmentReason { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
namespace Microsoft.FeatureManagement.Telemetry
{
/// <summary>
/// The reason the variant was assigned during the evaluation of a feature.
/// </summary>
public enum VariantAssignmentReason
{
/// <summary>
/// Variant allocation did not happend. No variant is assigned.
/// </summary>
None,

/// <summary>
/// The default variant is assigned when a feature flag is disabled.
/// </summary>
DefaultWhenDisabled,

/// <summary>
/// The default variant is assigned because of no applicable user/group/percentile allocation when a feature flag is enabled.
/// </summary>
DefaultWhenEnabled,

/// <summary>
/// The variant is assigned because of the user allocation when a feature flag is enabled.
/// </summary>
User,

/// <summary>
/// The variant is assigned because of the group allocation when a feature flag is enabled.
/// </summary>
Group,

/// <summary>
/// The variant is assigned because of the percentile allocation when a feature flag is enabled.
/// </summary>
Percentile
}
}
Loading