Skip to content

Commit ac3e927

Browse files
authored
feat: Add variation version to AI metric data (#71)
1 parent 6d54a0d commit ac3e927

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

pkgs/sdk/server-ai/src/Config/LdAiConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ internal LdAiConfig(bool enabled, IEnumerable<Message> messages, Meta meta, Mode
223223
model?.Custom ?? new Dictionary<string, LdValue>());
224224
Messages = messages?.ToList() ?? new List<Message>();
225225
VariationKey = meta?.VariationKey ?? "";
226+
Version = meta?.Version ?? 1;
226227
Enabled = enabled;
227228
Provider = new ModelProvider(provider?.Name ?? "");
228229
}
@@ -234,6 +235,7 @@ internal LdValue ToLdValue()
234235
new Dictionary<string, LdValue>
235236
{
236237
{ "variationKey", LdValue.Of(VariationKey) },
238+
{ "version", LdValue.Of(Version) },
237239
{ "enabled", LdValue.Of(Enabled) }
238240
}) },
239241
{ "messages", LdValue.ArrayFrom(Messages.Select(m => LdValue.ObjectFrom(new Dictionary<string, LdValue>
@@ -271,6 +273,11 @@ internal LdValue ToLdValue()
271273
/// </summary>
272274
public string VariationKey { get; }
273275

276+
/// <summary>
277+
/// This field meant for internal LaunchDarkly usage.
278+
/// </summary>
279+
public int Version { get; }
280+
274281
/// <summary>
275282
/// Convenient helper that returns a disabled LdAiConfig.
276283
/// </summary>

pkgs/sdk/server-ai/src/DataModel/DataModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public class Meta
3333
[JsonPropertyName("variationKey")]
3434
public string VariationKey { get; set; }
3535

36+
/// <summary>
37+
/// The variation version.
38+
/// </summary>
39+
[JsonPropertyName("version")]
40+
public int? Version { get; set; }
41+
3642
/// <summary>
3743
/// If the config is enabled.
3844
/// </summary>

pkgs/sdk/server-ai/src/LdAiConfigTracker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public LdAiConfigTracker(ILaunchDarklyClient client, string configKey, LdAiConfi
4646
_trackData = LdValue.ObjectFrom(new Dictionary<string, LdValue>
4747
{
4848
{ "variationKey", LdValue.Of(config.VariationKey)},
49+
{ "version", LdValue.Of(config.Version)},
4950
{ "configKey" , LdValue.Of(configKey ?? throw new ArgumentNullException(nameof(configKey))) }
5051
});
5152
}

pkgs/sdk/server-ai/test/LdAiConfigTrackerTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void CanTrackDuration()
4343
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
4444
{
4545
{ "variationKey", LdValue.Of(config.VariationKey) },
46+
{ "version", LdValue.Of(config.Version) },
4647
{ "configKey", LdValue.Of(flagKey) }
4748
});
4849
var tracker = new LdAiConfigTracker(mockClient.Object, flagKey, config, context);
@@ -61,6 +62,7 @@ public void CanTrackTimeToFirstToken()
6162
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
6263
{
6364
{ "variationKey", LdValue.Of(config.VariationKey) },
65+
{ "version", LdValue.Of(config.Version) },
6466
{ "configKey", LdValue.Of(flagKey) }
6567
});
6668
var tracker = new LdAiConfigTracker(mockClient.Object, flagKey, config, context);
@@ -79,6 +81,7 @@ public void CanTrackSuccess()
7981
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
8082
{
8183
{ "variationKey", LdValue.Of(config.VariationKey) },
84+
{ "version", LdValue.Of(config.Version) },
8285
{ "configKey", LdValue.Of(flagKey) }
8386
});
8487

@@ -99,6 +102,7 @@ public void CanTrackError()
99102
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
100103
{
101104
{ "variationKey", LdValue.Of(config.VariationKey) },
105+
{ "version", LdValue.Of(config.Version) },
102106
{ "configKey", LdValue.Of(flagKey) }
103107
});
104108

@@ -119,6 +123,7 @@ public async void CanTrackDurationOfTask()
119123
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
120124
{
121125
{ "variationKey", LdValue.Of(config.VariationKey) },
126+
{ "version", LdValue.Of(config.Version) },
122127
{ "configKey", LdValue.Of(flagKey) }
123128
});
124129

@@ -153,6 +158,7 @@ public void CanTrackFeedback()
153158
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
154159
{
155160
{ "variationKey", LdValue.Of(config.VariationKey) },
161+
{ "version", LdValue.Of(config.Version) },
156162
{ "configKey", LdValue.Of(flagKey) }
157163
});
158164

@@ -174,6 +180,7 @@ public void CanTrackTokens()
174180
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
175181
{
176182
{ "variationKey", LdValue.Of(config.VariationKey) },
183+
{ "version", LdValue.Of(config.Version) },
177184
{ "configKey", LdValue.Of(flagKey) }
178185
});
179186

@@ -202,6 +209,7 @@ public void CanTrackResponseWithSpecificLatency()
202209
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
203210
{
204211
{ "variationKey", LdValue.Of(config.VariationKey) },
212+
{ "version", LdValue.Of(config.Version) },
205213
{ "configKey", LdValue.Of(flagKey) }
206214
});
207215

@@ -245,6 +253,7 @@ public void CanTrackResponseWithPartialData()
245253
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
246254
{
247255
{ "variationKey", LdValue.Of(config.VariationKey) },
256+
{ "version", LdValue.Of(config.Version) },
248257
{ "configKey", LdValue.Of(flagKey) }
249258
});
250259

@@ -279,6 +288,7 @@ public async Task CanTrackExceptionFromResponse()
279288
var data = LdValue.ObjectFrom(new Dictionary<string, LdValue>
280289
{
281290
{ "variationKey", LdValue.Of(config.VariationKey) },
291+
{ "version", LdValue.Of(config.Version) },
282292
{ "configKey", LdValue.Of(flagKey) }
283293
});
284294

0 commit comments

Comments
 (0)