diff --git a/pkgs/sdk/server-ai/src/LdAiClient.cs b/pkgs/sdk/server-ai/src/LdAiClient.cs index 0e08747a..f7528ab7 100644 --- a/pkgs/sdk/server-ai/src/LdAiClient.cs +++ b/pkgs/sdk/server-ai/src/LdAiClient.cs @@ -47,6 +47,7 @@ public LdAiClient(ILaunchDarklyClient client) public ILdAiConfigTracker Config(string key, Context context, LdAiConfig defaultValue, IReadOnlyDictionary variables = null) { + _client.Track("$ld:ai:config:function:single", context, LdValue.Of(key), 1); var result = _client.JsonVariation(key, context, defaultValue.ToLdValue()); diff --git a/pkgs/sdk/server-ai/test/LdAiClientTest.cs b/pkgs/sdk/server-ai/test/LdAiClientTest.cs index e8cce999..f650c2b1 100644 --- a/pkgs/sdk/server-ai/test/LdAiClientTest.cs +++ b/pkgs/sdk/server-ai/test/LdAiClientTest.cs @@ -49,6 +49,53 @@ public void ReturnsDefaultConfigWhenGivenInvalidVariation() Assert.Equal(defaultConfig, tracker.Config); } + [Fact] + public void ConfigMethodCallsTrackWithCorrectParameters() + { + var mockClient = new Mock(); + var context = Context.New(ContextKind.Default, "user-key"); + var configKey = "test-config-key"; + + mockClient.Setup(c => c.JsonVariation( + It.IsAny(), + It.IsAny(), + It.IsAny())) + .Returns(LdValue.ObjectFrom(new Dictionary + { + ["_ldMeta"] = LdValue.ObjectFrom(new Dictionary + { + ["enabled"] = LdValue.Of(true), + ["variationKey"] = LdValue.Of("test-variation"), + ["version"] = LdValue.Of(1) + }), + ["model"] = LdValue.ObjectFrom(new Dictionary + { + ["name"] = LdValue.Of("test-model") + }), + ["provider"] = LdValue.ObjectFrom(new Dictionary + { + ["name"] = LdValue.Of("test-provider") + }), + ["messages"] = LdValue.ArrayOf() + })); + + var mockLogger = new Mock(); + mockClient.Setup(x => x.GetLogger()).Returns(mockLogger.Object); + + var client = new LdAiClient(mockClient.Object); + var defaultConfig = LdAiConfig.New().Build(); + + var tracker = client.Config(configKey, context, defaultConfig); + + mockClient.Verify(c => c.Track( + "$ld:ai:config:function:single", + context, + LdValue.Of(configKey), + 1), Times.Once); + + Assert.NotNull(tracker); + } + private const string MetaDisabledExplicitly = """ { "_ldMeta": {"variationKey": "1", "enabled": false},