@@ -47,31 +47,34 @@ func TestTracker_NewDoesNotPanicWithConfig(t *testing.T) {
47
47
})
48
48
}
49
49
50
- func makeTrackData (configKey , variationKey string , version int ) ldvalue.Value {
50
+ func makeTrackData (configKey , variationKey string , version int , config * Config ) ldvalue.Value {
51
51
return ldvalue .ObjectBuild ().
52
52
Set ("variationKey" , ldvalue .String (variationKey )).
53
53
Set ("configKey" , ldvalue .String (configKey )).
54
54
Set ("version" , ldvalue .Int (version )).
55
+ Set ("providerName" , ldvalue .String (config .ProviderName ())).
56
+ Set ("modelName" , ldvalue .String (config .ModelName ())).
55
57
Build ()
56
58
}
57
59
58
60
func TestTracker_TrackSuccess (t * testing.T ) {
59
61
events := newMockEvents ()
60
- tracker := newTracker ("key" , "variationKey" , 1 , events , & Config {}, ldcontext .New ("key" ), nil )
62
+ config := & Config {}
63
+ tracker := newTracker ("key" , "variationKey" , 1 , events , config , ldcontext .New ("key" ), nil )
61
64
assert .NoError (t , tracker .TrackSuccess ())
62
65
63
66
expectedEvents := []trackEvent {
64
67
{
65
68
name : "$ld:ai:generation" ,
66
69
context : ldcontext .New ("key" ),
67
70
metricValue : 1.0 ,
68
- data : makeTrackData ("key" , "variationKey" , 1 ),
71
+ data : makeTrackData ("key" , "variationKey" , 1 , config ),
69
72
},
70
73
{
71
74
name : "$ld:ai:generation:success" ,
72
75
context : ldcontext .New ("key" ),
73
76
metricValue : 1.0 ,
74
- data : makeTrackData ("key" , "variationKey" , 1 ),
77
+ data : makeTrackData ("key" , "variationKey" , 1 , config ),
75
78
},
76
79
}
77
80
@@ -80,21 +83,22 @@ func TestTracker_TrackSuccess(t *testing.T) {
80
83
81
84
func TestTracker_TrackError (t * testing.T ) {
82
85
events := newMockEvents ()
83
- tracker := newTracker ("key" , "variationKey" , 2 , events , & Config {}, ldcontext .New ("key" ), nil )
86
+ config := & Config {}
87
+ tracker := newTracker ("key" , "variationKey" , 2 , events , config , ldcontext .New ("key" ), nil )
84
88
assert .NoError (t , tracker .TrackError ())
85
89
86
90
expectedEvents := []trackEvent {
87
91
{
88
92
name : "$ld:ai:generation" ,
89
93
context : ldcontext .New ("key" ),
90
94
metricValue : 1.0 ,
91
- data : makeTrackData ("key" , "variationKey" , 2 ),
95
+ data : makeTrackData ("key" , "variationKey" , 2 , config ),
92
96
},
93
97
{
94
98
name : "$ld:ai:generation:error" ,
95
99
context : ldcontext .New ("key" ),
96
100
metricValue : 1.0 ,
97
- data : makeTrackData ("key" , "variationKey" , 2 ),
101
+ data : makeTrackData ("key" , "variationKey" , 2 , config ),
98
102
},
99
103
}
100
104
@@ -103,7 +107,8 @@ func TestTracker_TrackError(t *testing.T) {
103
107
104
108
func TestTracker_TrackRequest (t * testing.T ) {
105
109
events := newMockEvents ()
106
- tracker := newTracker ("key" , "variationKey" , 3 , events , & Config {}, ldcontext .New ("key" ), nil )
110
+ config := & Config {}
111
+ tracker := newTracker ("key" , "variationKey" , 3 , events , config , ldcontext .New ("key" ), nil )
107
112
108
113
expectedResponse := ProviderResponse {
109
114
Usage : TokenUsage {
@@ -127,31 +132,31 @@ func TestTracker_TrackRequest(t *testing.T) {
127
132
name : "$ld:ai:generation" ,
128
133
context : ldcontext .New ("key" ),
129
134
metricValue : 1 ,
130
- data : makeTrackData ("key" , "variationKey" , 3 ),
135
+ data : makeTrackData ("key" , "variationKey" , 3 , config ),
131
136
},
132
137
{
133
138
name : "$ld:ai:generation:success" ,
134
139
context : ldcontext .New ("key" ),
135
140
metricValue : 1 ,
136
- data : makeTrackData ("key" , "variationKey" , 3 ),
141
+ data : makeTrackData ("key" , "variationKey" , 3 , config ),
137
142
},
138
143
{
139
144
name : "$ld:ai:duration:total" ,
140
145
context : ldcontext .New ("key" ),
141
146
metricValue : 10.0 ,
142
- data : makeTrackData ("key" , "variationKey" , 3 ),
147
+ data : makeTrackData ("key" , "variationKey" , 3 , config ),
143
148
},
144
149
{
145
150
name : "$ld:ai:tokens:total" ,
146
151
context : ldcontext .New ("key" ),
147
152
metricValue : 1 ,
148
- data : makeTrackData ("key" , "variationKey" , 3 ),
153
+ data : makeTrackData ("key" , "variationKey" , 3 , config ),
149
154
},
150
155
{
151
156
name : "$ld:ai:tokens:ttf" ,
152
157
context : ldcontext .New ("key" ),
153
158
metricValue : 42.0 ,
154
- data : makeTrackData ("key" , "variationKey" , 3 ),
159
+ data : makeTrackData ("key" , "variationKey" , 3 , config ),
155
160
},
156
161
}
157
162
@@ -191,9 +196,10 @@ func (m mockStopwatch) Stop() time.Duration {
191
196
192
197
func TestTracker_LatencyMeasuredIfNotProvided (t * testing.T ) {
193
198
events := newMockEvents ()
199
+ config := & Config {}
194
200
195
201
tracker := newTrackerWithStopwatch (
196
- "key" , "variationKey" , 5 , events , & Config {} , ldcontext .New ("key" ), nil , mockStopwatch (42 * time .Millisecond ))
202
+ "key" , "variationKey" , 5 , events , config , ldcontext .New ("key" ), nil , mockStopwatch (42 * time .Millisecond ))
197
203
198
204
expectedResponse := ProviderResponse {
199
205
Usage : TokenUsage {
@@ -216,23 +222,25 @@ func TestTracker_LatencyMeasuredIfNotProvided(t *testing.T) {
216
222
217
223
func TestTracker_TrackDuration (t * testing.T ) {
218
224
events := newMockEvents ()
219
- tracker := newTracker ("key" , "variationKey" , 6 , events , & Config {}, ldcontext .New ("key" ), nil )
225
+ config := & Config {}
226
+ tracker := newTracker ("key" , "variationKey" , 6 , events , config , ldcontext .New ("key" ), nil )
220
227
221
228
assert .NoError (t , tracker .TrackDuration (time .Millisecond * 10 ))
222
229
223
230
expectedEvent := trackEvent {
224
231
name : "$ld:ai:duration:total" ,
225
232
context : ldcontext .New ("key" ),
226
233
metricValue : 10.0 ,
227
- data : makeTrackData ("key" , "variationKey" , 6 ),
234
+ data : makeTrackData ("key" , "variationKey" , 6 , config ),
228
235
}
229
236
230
237
assert .ElementsMatch (t , []trackEvent {expectedEvent }, events .events )
231
238
}
232
239
233
240
func TestTracker_TrackFeedback (t * testing.T ) {
234
241
events := newMockEvents ()
235
- tracker := newTracker ("key" , "variationKey" , 7 , events , & Config {}, ldcontext .New ("key" ), nil )
242
+ config := & Config {}
243
+ tracker := newTracker ("key" , "variationKey" , 7 , events , config , ldcontext .New ("key" ), nil )
236
244
237
245
assert .NoError (t , tracker .TrackFeedback (FeedbackPositive ))
238
246
assert .NoError (t , tracker .TrackFeedback (FeedbackNegative ))
@@ -242,14 +250,14 @@ func TestTracker_TrackFeedback(t *testing.T) {
242
250
name : "$ld:ai:feedback:user:positive" ,
243
251
context : ldcontext .New ("key" ),
244
252
metricValue : 1.0 ,
245
- data : makeTrackData ("key" , "variationKey" , 7 ),
253
+ data : makeTrackData ("key" , "variationKey" , 7 , config ),
246
254
}
247
255
248
256
expectedNegativeEvent := trackEvent {
249
257
name : "$ld:ai:feedback:user:negative" ,
250
258
context : ldcontext .New ("key" ),
251
259
metricValue : 1.0 ,
252
- data : makeTrackData ("key" , "variationKey" , 7 ),
260
+ data : makeTrackData ("key" , "variationKey" , 7 , config ),
253
261
}
254
262
255
263
assert .ElementsMatch (t , []trackEvent {expectedPositiveEvent , expectedNegativeEvent }, events .events )
@@ -258,7 +266,8 @@ func TestTracker_TrackFeedback(t *testing.T) {
258
266
func TestTracker_TrackUsage (t * testing.T ) {
259
267
t .Run ("only one field set, only one event" , func (t * testing.T ) {
260
268
events := newMockEvents ()
261
- tracker := newTracker ("key" , "variationKey" , 8 , events , & Config {}, ldcontext .New ("key" ), nil )
269
+ config := & Config {}
270
+ tracker := newTracker ("key" , "variationKey" , 8 , events , config , ldcontext .New ("key" ), nil )
262
271
263
272
assert .NoError (t , tracker .TrackUsage (TokenUsage {
264
273
Total : 42 ,
@@ -268,15 +277,16 @@ func TestTracker_TrackUsage(t *testing.T) {
268
277
name : "$ld:ai:tokens:total" ,
269
278
context : ldcontext .New ("key" ),
270
279
metricValue : 42.0 ,
271
- data : makeTrackData ("key" , "variationKey" , 8 ),
280
+ data : makeTrackData ("key" , "variationKey" , 8 , config ),
272
281
}
273
282
274
283
assert .ElementsMatch (t , []trackEvent {expectedEvent }, events .events )
275
284
})
276
285
277
286
t .Run ("all fields set, all events" , func (t * testing.T ) {
278
287
events := newMockEvents ()
279
- tracker := newTracker ("key" , "variationKey" , 9 , events , & Config {}, ldcontext .New ("key" ), nil )
288
+ config := & Config {}
289
+ tracker := newTracker ("key" , "variationKey" , 9 , events , config , ldcontext .New ("key" ), nil )
280
290
281
291
assert .NoError (t , tracker .TrackUsage (TokenUsage {
282
292
Total : 42 ,
@@ -288,21 +298,21 @@ func TestTracker_TrackUsage(t *testing.T) {
288
298
name : "$ld:ai:tokens:total" ,
289
299
context : ldcontext .New ("key" ),
290
300
metricValue : 42.0 ,
291
- data : makeTrackData ("key" , "variationKey" , 9 ),
301
+ data : makeTrackData ("key" , "variationKey" , 9 , config ),
292
302
}
293
303
294
304
expectedInput := trackEvent {
295
305
name : "$ld:ai:tokens:input" ,
296
306
context : ldcontext .New ("key" ),
297
307
metricValue : 20.0 ,
298
- data : makeTrackData ("key" , "variationKey" , 9 ),
308
+ data : makeTrackData ("key" , "variationKey" , 9 , config ),
299
309
}
300
310
301
311
expectedOutput := trackEvent {
302
312
name : "$ld:ai:tokens:output" ,
303
313
context : ldcontext .New ("key" ),
304
314
metricValue : 22.0 ,
305
- data : makeTrackData ("key" , "variationKey" , 9 ),
315
+ data : makeTrackData ("key" , "variationKey" , 9 , config ),
306
316
}
307
317
308
318
assert .ElementsMatch (t , []trackEvent {expectedTotal , expectedInput , expectedOutput }, events .events )
0 commit comments