Skip to content
Closed
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 @@ -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;
Expand Down Expand Up @@ -53,6 +54,12 @@ public async Task<IActionResult> 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)
{
Expand Down Expand Up @@ -139,21 +146,34 @@ 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);
}
}
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")]
Expand Down
Loading