@@ -80,10 +80,12 @@ describe('GoogleCloudMetrics', () => {
80
80
assert . equal ( requestCounter . value , 2 ) ;
81
81
assert . equal ( requestCounter . attributes . name , 'testFlow' ) ;
82
82
assert . equal ( requestCounter . attributes . source , 'ts' ) ;
83
+ assert . equal ( requestCounter . attributes . status , 'success' ) ;
83
84
assert . ok ( requestCounter . attributes . sourceVersion ) ;
84
85
assert . equal ( latencyHistogram . value . count , 2 ) ;
85
86
assert . equal ( latencyHistogram . attributes . name , 'testFlow' ) ;
86
87
assert . equal ( latencyHistogram . attributes . source , 'ts' ) ;
88
+ assert . equal ( latencyHistogram . attributes . status , 'success' ) ;
87
89
assert . ok ( latencyHistogram . attributes . sourceVersion ) ;
88
90
} ) ;
89
91
@@ -102,6 +104,7 @@ describe('GoogleCloudMetrics', () => {
102
104
assert . equal ( requestCounter . attributes . name , 'testFlow' ) ;
103
105
assert . equal ( requestCounter . attributes . source , 'ts' ) ;
104
106
assert . equal ( requestCounter . attributes . error , 'TypeError' ) ;
107
+ assert . equal ( requestCounter . attributes . status , 'failure' ) ;
105
108
} ) ;
106
109
107
110
it ( 'writes action metrics' , async ( ) => {
@@ -122,10 +125,12 @@ describe('GoogleCloudMetrics', () => {
122
125
assert . equal ( requestCounter . value , 6 ) ;
123
126
assert . equal ( requestCounter . attributes . name , 'testAction' ) ;
124
127
assert . equal ( requestCounter . attributes . source , 'ts' ) ;
128
+ assert . equal ( requestCounter . attributes . status , 'success' ) ;
125
129
assert . ok ( requestCounter . attributes . sourceVersion ) ;
126
130
assert . equal ( latencyHistogram . value . count , 6 ) ;
127
131
assert . equal ( latencyHistogram . attributes . name , 'testAction' ) ;
128
132
assert . equal ( latencyHistogram . attributes . source , 'ts' ) ;
133
+ assert . equal ( latencyHistogram . attributes . status , 'success' ) ;
129
134
assert . ok ( latencyHistogram . attributes . sourceVersion ) ;
130
135
} ) ;
131
136
@@ -163,6 +168,7 @@ describe('GoogleCloudMetrics', () => {
163
168
assert . equal ( requestCounter . value , 1 ) ;
164
169
assert . equal ( requestCounter . attributes . name , 'testActionWithFailure' ) ;
165
170
assert . equal ( requestCounter . attributes . source , 'ts' ) ;
171
+ assert . equal ( requestCounter . attributes . status , 'failure' ) ;
166
172
assert . equal ( requestCounter . attributes . error , 'TypeError' ) ;
167
173
} ) ;
168
174
@@ -253,6 +259,7 @@ describe('GoogleCloudMetrics', () => {
253
259
assert . equal ( metric . attributes . topK , 3 ) ;
254
260
assert . equal ( metric . attributes . topP , 5 ) ;
255
261
assert . equal ( metric . attributes . source , 'ts' ) ;
262
+ assert . equal ( metric . attributes . status , 'success' ) ;
256
263
assert . ok ( metric . attributes . sourceVersion ) ;
257
264
}
258
265
} ) ;
@@ -285,6 +292,7 @@ describe('GoogleCloudMetrics', () => {
285
292
assert . equal ( requestCounter . attributes . topK , 3 ) ;
286
293
assert . equal ( requestCounter . attributes . topP , 5 ) ;
287
294
assert . equal ( requestCounter . attributes . source , 'ts' ) ;
295
+ assert . equal ( requestCounter . attributes . status , 'failure' ) ;
288
296
assert . equal ( requestCounter . attributes . error , 'TypeError' ) ;
289
297
assert . ok ( requestCounter . attributes . sourceVersion ) ;
290
298
} ) ;
@@ -374,6 +382,9 @@ describe('GoogleCloudMetrics', () => {
374
382
const pathCounterPoints = await getCounterDataPoints (
375
383
'genkit/flow/path/requests'
376
384
) ;
385
+ const pathLatencyPoints = await getHistogramDataPoints (
386
+ 'genkit/flow/path/latency'
387
+ ) ;
377
388
const paths = new Set (
378
389
pathCounterPoints . map ( ( point ) => point . attributes . path )
379
390
) ;
@@ -382,9 +393,50 @@ describe('GoogleCloudMetrics', () => {
382
393
assert . equal ( point . value , 1 ) ;
383
394
assert . equal ( point . attributes . flowName , 'pathTestFlow' ) ;
384
395
assert . equal ( point . attributes . source , 'ts' ) ;
385
- assert . equal ( point . attributes . success , 'success' ) ;
396
+ assert . equal ( point . attributes . status , 'success' ) ;
386
397
assert . ok ( point . attributes . sourceVersion ) ;
387
398
} ) ;
399
+ pathLatencyPoints . forEach ( ( point ) => {
400
+ assert . equal ( point . value . count , 1 ) ;
401
+ assert . equal ( point . attributes . flowName , 'pathTestFlow' ) ;
402
+ assert . equal ( point . attributes . source , 'ts' ) ;
403
+ assert . equal ( point . attributes . status , 'success' ) ;
404
+ assert . ok ( point . attributes . sourceVersion ) ;
405
+ } ) ;
406
+ } ) ;
407
+
408
+ it ( 'writes flow path failure metrics' , async ( ) => {
409
+ const flow = createFlow ( 'testFlow' , async ( ) => {
410
+ const subPath = await run ( 'sub-action' , async ( ) => {
411
+ return 'done' ;
412
+ } ) ;
413
+ return Promise . reject ( new Error ( 'failed' ) ) ;
414
+ } ) ;
415
+
416
+ assert . rejects ( async ( ) => {
417
+ await runFlow ( flow ) ;
418
+ } ) ;
419
+
420
+ const reqPoints = await getCounterDataPoints ( 'genkit/flow/path/requests' ) ;
421
+ const reqStatuses = reqPoints . map ( ( p ) => [
422
+ p . attributes . path ,
423
+ p . attributes . status ,
424
+ ] ) ;
425
+ assert . deepEqual ( reqStatuses , [
426
+ [ '/{testFlow,t:flow}/{sub-action,t:flowStep}' , 'success' ] ,
427
+ [ '/{testFlow,t:flow}' , 'failure' ] ,
428
+ ] ) ;
429
+ const latencyPoints = await getHistogramDataPoints (
430
+ 'genkit/flow/path/latency'
431
+ ) ;
432
+ const latencyStatuses = latencyPoints . map ( ( p ) => [
433
+ p . attributes . path ,
434
+ p . attributes . status ,
435
+ ] ) ;
436
+ assert . deepEqual ( latencyStatuses , [
437
+ [ '/{testFlow,t:flow}/{sub-action,t:flowStep}' , 'success' ] ,
438
+ [ '/{testFlow,t:flow}' , 'failure' ] ,
439
+ ] ) ;
388
440
} ) ;
389
441
390
442
describe ( 'Configuration' , ( ) => {
@@ -453,23 +505,33 @@ describe('GoogleCloudMetrics', () => {
453
505
return getCounterDataPoints ( metricName ) . then ( ( points ) => points . at ( - 1 ) ) ;
454
506
}
455
507
456
- /** Finds a histogram metric with the given name in the in memory exporter */
457
- async function getHistogramMetric (
508
+ /**
509
+ * Finds all datapoints for a histogram metric with the given name in the in
510
+ * memory exporter.
511
+ */
512
+ async function getHistogramDataPoints (
458
513
metricName : string
459
- ) : Promise < DataPoint < Histogram > > {
514
+ ) : Promise < List < DataPoint < Histogram > > > {
460
515
const genkitMetrics = await getGenkitMetrics ( ) ;
461
516
const histogramMetric : HistogramMetricData = genkitMetrics . metrics . find (
462
517
( e ) =>
463
518
e . descriptor . name === metricName && e . descriptor . type === 'HISTOGRAM'
464
519
) ;
465
520
if ( histogramMetric ) {
466
- return histogramMetric . dataPoints . at ( - 1 ) ;
521
+ return histogramMetric . dataPoints ;
467
522
}
468
523
assert . fail (
469
524
`No histogram metric named ${ metricName } was found. Only found: ${ genkitMetrics . metrics . map ( ( e ) => e . descriptor . name ) } `
470
525
) ;
471
526
}
472
527
528
+ /** Finds a histogram metric with the given name in the in memory exporter */
529
+ async function getHistogramMetric (
530
+ metricName : string
531
+ ) : Promise < DataPoint < Histogram > > {
532
+ return getHistogramDataPoints ( metricName ) . then ( ( points ) => points . at ( - 1 ) ) ;
533
+ }
534
+
473
535
/** Helper to create a flow with no inputs or outputs */
474
536
function createFlow ( name : string , fn : ( ) => Promise < void > = async ( ) => { } ) {
475
537
return defineFlow (
0 commit comments