@@ -13,26 +13,26 @@ const mockLdClient: LDClientMin = {
13
13
14
14
const testContext : LDContext = { kind : 'user' , key : 'test-user' } ;
15
15
const configKey = 'test-config' ;
16
- const versionKey = 'v1' ;
16
+ const variationKey = 'v1' ;
17
17
18
18
beforeEach ( ( ) => {
19
19
jest . clearAllMocks ( ) ;
20
20
} ) ;
21
21
22
22
it ( 'tracks duration' , ( ) => {
23
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
23
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
24
24
tracker . trackDuration ( 1000 ) ;
25
25
26
26
expect ( mockTrack ) . toHaveBeenCalledWith (
27
27
'$ld:ai:duration:total' ,
28
28
testContext ,
29
- { configKey, versionKey } ,
29
+ { configKey, variationKey } ,
30
30
1000 ,
31
31
) ;
32
32
} ) ;
33
33
34
34
it ( 'tracks duration of async function' , async ( ) => {
35
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
35
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
36
36
jest . spyOn ( global . Date , 'now' ) . mockReturnValueOnce ( 1000 ) . mockReturnValueOnce ( 2000 ) ;
37
37
38
38
const result = await tracker . trackDurationOf ( async ( ) => 'test-result' ) ;
@@ -41,49 +41,49 @@ it('tracks duration of async function', async () => {
41
41
expect ( mockTrack ) . toHaveBeenCalledWith (
42
42
'$ld:ai:duration:total' ,
43
43
testContext ,
44
- { configKey, versionKey } ,
44
+ { configKey, variationKey } ,
45
45
1000 ,
46
46
) ;
47
47
} ) ;
48
48
49
49
it ( 'tracks positive feedback' , ( ) => {
50
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
50
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
51
51
tracker . trackFeedback ( { kind : LDFeedbackKind . Positive } ) ;
52
52
53
53
expect ( mockTrack ) . toHaveBeenCalledWith (
54
54
'$ld:ai:feedback:user:positive' ,
55
55
testContext ,
56
- { configKey, versionKey } ,
56
+ { configKey, variationKey } ,
57
57
1 ,
58
58
) ;
59
59
} ) ;
60
60
61
61
it ( 'tracks negative feedback' , ( ) => {
62
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
62
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
63
63
tracker . trackFeedback ( { kind : LDFeedbackKind . Negative } ) ;
64
64
65
65
expect ( mockTrack ) . toHaveBeenCalledWith (
66
66
'$ld:ai:feedback:user:negative' ,
67
67
testContext ,
68
- { configKey, versionKey } ,
68
+ { configKey, variationKey } ,
69
69
1 ,
70
70
) ;
71
71
} ) ;
72
72
73
73
it ( 'tracks success' , ( ) => {
74
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
74
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
75
75
tracker . trackSuccess ( ) ;
76
76
77
77
expect ( mockTrack ) . toHaveBeenCalledWith (
78
78
'$ld:ai:generation' ,
79
79
testContext ,
80
- { configKey, versionKey } ,
80
+ { configKey, variationKey } ,
81
81
1 ,
82
82
) ;
83
83
} ) ;
84
84
85
85
it ( 'tracks OpenAI usage' , async ( ) => {
86
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
86
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
87
87
jest . spyOn ( global . Date , 'now' ) . mockReturnValueOnce ( 1000 ) . mockReturnValueOnce ( 2000 ) ;
88
88
89
89
const TOTAL_TOKENS = 100 ;
@@ -101,41 +101,41 @@ it('tracks OpenAI usage', async () => {
101
101
expect ( mockTrack ) . toHaveBeenCalledWith (
102
102
'$ld:ai:duration:total' ,
103
103
testContext ,
104
- { configKey, versionKey } ,
104
+ { configKey, variationKey } ,
105
105
1000 ,
106
106
) ;
107
107
108
108
expect ( mockTrack ) . toHaveBeenCalledWith (
109
109
'$ld:ai:generation' ,
110
110
testContext ,
111
- { configKey, versionKey } ,
111
+ { configKey, variationKey } ,
112
112
1 ,
113
113
) ;
114
114
115
115
expect ( mockTrack ) . toHaveBeenCalledWith (
116
116
'$ld:ai:tokens:total' ,
117
117
testContext ,
118
- { configKey, versionKey } ,
118
+ { configKey, variationKey } ,
119
119
TOTAL_TOKENS ,
120
120
) ;
121
121
122
122
expect ( mockTrack ) . toHaveBeenCalledWith (
123
123
'$ld:ai:tokens:input' ,
124
124
testContext ,
125
- { configKey, versionKey } ,
125
+ { configKey, variationKey } ,
126
126
PROMPT_TOKENS ,
127
127
) ;
128
128
129
129
expect ( mockTrack ) . toHaveBeenCalledWith (
130
130
'$ld:ai:tokens:output' ,
131
131
testContext ,
132
- { configKey, versionKey } ,
132
+ { configKey, variationKey } ,
133
133
COMPLETION_TOKENS ,
134
134
) ;
135
135
} ) ;
136
136
137
137
it ( 'tracks Bedrock conversation with successful response' , ( ) => {
138
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
138
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
139
139
140
140
const TOTAL_TOKENS = 100 ;
141
141
const PROMPT_TOKENS = 49 ;
@@ -156,41 +156,41 @@ it('tracks Bedrock conversation with successful response', () => {
156
156
expect ( mockTrack ) . toHaveBeenCalledWith (
157
157
'$ld:ai:generation' ,
158
158
testContext ,
159
- { configKey, versionKey } ,
159
+ { configKey, variationKey } ,
160
160
1 ,
161
161
) ;
162
162
163
163
expect ( mockTrack ) . toHaveBeenCalledWith (
164
164
'$ld:ai:duration:total' ,
165
165
testContext ,
166
- { configKey, versionKey } ,
166
+ { configKey, variationKey } ,
167
167
500 ,
168
168
) ;
169
169
170
170
expect ( mockTrack ) . toHaveBeenCalledWith (
171
171
'$ld:ai:tokens:total' ,
172
172
testContext ,
173
- { configKey, versionKey } ,
173
+ { configKey, variationKey } ,
174
174
TOTAL_TOKENS ,
175
175
) ;
176
176
177
177
expect ( mockTrack ) . toHaveBeenCalledWith (
178
178
'$ld:ai:tokens:input' ,
179
179
testContext ,
180
- { configKey, versionKey } ,
180
+ { configKey, variationKey } ,
181
181
PROMPT_TOKENS ,
182
182
) ;
183
183
184
184
expect ( mockTrack ) . toHaveBeenCalledWith (
185
185
'$ld:ai:tokens:output' ,
186
186
testContext ,
187
- { configKey, versionKey } ,
187
+ { configKey, variationKey } ,
188
188
COMPLETION_TOKENS ,
189
189
) ;
190
190
} ) ;
191
191
192
192
it ( 'tracks Bedrock conversation with error response' , ( ) => {
193
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
193
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
194
194
195
195
const response = {
196
196
$metadata : { httpStatusCode : 400 } ,
@@ -204,7 +204,7 @@ it('tracks Bedrock conversation with error response', () => {
204
204
} ) ;
205
205
206
206
it ( 'tracks tokens' , ( ) => {
207
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
207
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
208
208
209
209
const TOTAL_TOKENS = 100 ;
210
210
const PROMPT_TOKENS = 49 ;
@@ -219,27 +219,27 @@ it('tracks tokens', () => {
219
219
expect ( mockTrack ) . toHaveBeenCalledWith (
220
220
'$ld:ai:tokens:total' ,
221
221
testContext ,
222
- { configKey, versionKey } ,
222
+ { configKey, variationKey } ,
223
223
TOTAL_TOKENS ,
224
224
) ;
225
225
226
226
expect ( mockTrack ) . toHaveBeenCalledWith (
227
227
'$ld:ai:tokens:input' ,
228
228
testContext ,
229
- { configKey, versionKey } ,
229
+ { configKey, variationKey } ,
230
230
PROMPT_TOKENS ,
231
231
) ;
232
232
233
233
expect ( mockTrack ) . toHaveBeenCalledWith (
234
234
'$ld:ai:tokens:output' ,
235
235
testContext ,
236
- { configKey, versionKey } ,
236
+ { configKey, variationKey } ,
237
237
COMPLETION_TOKENS ,
238
238
) ;
239
239
} ) ;
240
240
241
241
it ( 'only tracks non-zero token counts' , ( ) => {
242
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
242
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
243
243
244
244
tracker . trackTokens ( {
245
245
total : 0 ,
@@ -257,7 +257,7 @@ it('only tracks non-zero token counts', () => {
257
257
expect ( mockTrack ) . toHaveBeenCalledWith (
258
258
'$ld:ai:tokens:input' ,
259
259
testContext ,
260
- { configKey, versionKey } ,
260
+ { configKey, variationKey } ,
261
261
50 ,
262
262
) ;
263
263
@@ -270,15 +270,15 @@ it('only tracks non-zero token counts', () => {
270
270
} ) ;
271
271
272
272
it ( 'returns empty summary when no metrics tracked' , ( ) => {
273
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
273
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
274
274
275
275
const summary = tracker . getSummary ( ) ;
276
276
277
277
expect ( summary ) . toEqual ( { } ) ;
278
278
} ) ;
279
279
280
280
it ( 'summarizes tracked metrics' , ( ) => {
281
- const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , versionKey , testContext ) ;
281
+ const tracker = new LDAIConfigTrackerImpl ( mockLdClient , configKey , variationKey , testContext ) ;
282
282
283
283
tracker . trackDuration ( 1000 ) ;
284
284
tracker . trackTokens ( {
0 commit comments