diff --git a/utils/build/docker/dotnet/weblog/Controllers/FeatureFlagEvaluatorController.cs b/utils/build/docker/dotnet/weblog/Controllers/FeatureFlagEvaluatorController.cs index 183cd1bcf9f..4fd9ca6d826 100644 --- a/utils/build/docker/dotnet/weblog/Controllers/FeatureFlagEvaluatorController.cs +++ b/utils/build/docker/dotnet/weblog/Controllers/FeatureFlagEvaluatorController.cs @@ -7,6 +7,7 @@ using OpenFeature.Model; using System; using System.Collections.Generic; +using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; using System.Threading.Tasks; @@ -53,6 +54,12 @@ public async Task Evaluate([FromBody] EvaluateRequest request) try { + if (targetingKeys.Count > 1) + { + // Start burst tests in a fresh aggregation window, not just before a periodic flush. + await Datadog.Trace.Tracer.Instance.ForceFlushAsync(); + } + value = request.DefaultValue; foreach (var targetingKey in targetingKeys) { @@ -139,14 +146,12 @@ private static EvaluationContext CreateContext(EvaluateRequest request, string t { foreach (var attr in request.Attributes) { - // System.Text.Json deserializes to JsonElement, not string + // Preserve JSON types so the SDK receives the context the test sent. var value = attr.Value switch { - JsonElement jsonElement => jsonElement.ValueKind == JsonValueKind.String - ? jsonElement.GetString() - : jsonElement.ToString(), - string s => s, - _ => attr.Value?.ToString() + JsonElement jsonElement => JsonElementToValue(jsonElement), + string s => new Value(s), + _ => new Value(attr.Value?.ToString()) }; builder.Set(attr.Key, value); } @@ -154,6 +159,21 @@ private static EvaluationContext CreateContext(EvaluateRequest request, string t return builder.Build(); } + private static Value JsonElementToValue(JsonElement element) + { + return element.ValueKind switch + { + JsonValueKind.String => new Value(element.GetString()), + JsonValueKind.Number => new Value(element.GetDouble()), + JsonValueKind.True => new Value(true), + JsonValueKind.False => new Value(false), + JsonValueKind.Array => new Value(element.EnumerateArray().Select(JsonElementToValue).ToList()), + JsonValueKind.Object => new Value(new Structure(element.EnumerateObject() + .ToDictionary(property => property.Name, property => JsonElementToValue(property.Value)))), + _ => new Value() + }; + } + public class EvaluateRequest { [JsonPropertyName("flag")]