@@ -51,9 +51,10 @@ import {
5151 SEMATTRS_DB_STATEMENT ,
5252} from '@opentelemetry/semantic-conventions' ;
5353import {
54+ ATTR_DB_CLIENT_CONNECTION_STATE ,
5455 METRIC_DB_CLIENT_CONNECTION_COUNT ,
5556 METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS ,
56- ATTR_DB_CLIENT_CONNECTION_STATE ,
57+ METRIC_DB_CLIENT_OPERATION_DURATION ,
5758} from '@opentelemetry/semantic-conventions/incubating' ;
5859
5960const memoryExporter = new InMemorySpanExporter ( ) ;
@@ -524,6 +525,11 @@ describe('pg-pool', () => {
524525 ) ;
525526
526527 const metrics = resourceMetrics . scopeMetrics [ 0 ] . metrics ;
528+ assert . strictEqual (
529+ metrics [ 0 ] . descriptor . name ,
530+ METRIC_DB_CLIENT_OPERATION_DURATION
531+ ) ;
532+
527533 assert . strictEqual (
528534 metrics [ 1 ] . descriptor . name ,
529535 METRIC_DB_CLIENT_CONNECTION_COUNT
@@ -573,6 +579,40 @@ describe('pg-pool', () => {
573579 } ) ;
574580 } ) ;
575581
582+ it ( 'should generate `db.client.*` metrics (Promises-style)' , async ( ...args ) => {
583+ const client = await pool . connect ( ) ;
584+
585+ try {
586+ const ret = await client . query ( 'SELECT NOW()' ) ;
587+ assert . ok ( ret ) ;
588+ } finally {
589+ client . release ( ) ;
590+ }
591+
592+ const { resourceMetrics, errors } = await metricReader . collect ( ) ;
593+ assert . deepEqual (
594+ errors ,
595+ [ ] ,
596+ 'expected no errors from the callback during metric collection'
597+ ) ;
598+
599+ // We just test the expected metric *names* here. The particulars of the
600+ // metric values are already tested in other test cases.
601+ const metrics = resourceMetrics . scopeMetrics [ 0 ] . metrics ;
602+ assert . strictEqual (
603+ metrics [ 0 ] . descriptor . name ,
604+ METRIC_DB_CLIENT_OPERATION_DURATION
605+ ) ;
606+ assert . strictEqual (
607+ metrics [ 1 ] . descriptor . name ,
608+ METRIC_DB_CLIENT_CONNECTION_COUNT
609+ ) ;
610+ assert . strictEqual (
611+ metrics [ 2 ] . descriptor . name ,
612+ METRIC_DB_CLIENT_CONNECTION_PENDING_REQUESTS
613+ ) ;
614+ } ) ;
615+
576616 it ( 'should not add duplicate event listeners to PgPool events' , done => {
577617 const poolAux : pgPool < pg . Client > = new pgPool ( CONFIG ) ;
578618 let completed = 0 ;
0 commit comments