1
1
import { Hub } from '@sentry/hub' ;
2
2
import { EventProcessor , Integration } from '@sentry/types' ;
3
- import { fill , loadModule , logger } from '@sentry/utils' ;
3
+ import { fill , isThenable , loadModule , logger } from '@sentry/utils' ;
4
4
5
5
interface PgClient {
6
6
prototype : {
@@ -36,6 +36,7 @@ export class Postgres implements Integration {
36
36
* function (query, params, callback) => void
37
37
* function (query) => Promise
38
38
* function (query, params) => Promise
39
+ * function (pg.Cursor) => pg.Cursor
39
40
*/
40
41
fill ( pkg . Client . prototype , 'query' , function ( orig : ( ) => void | Promise < unknown > ) {
41
42
return function ( this : unknown , config : unknown , values : unknown , callback : unknown ) {
@@ -60,10 +61,17 @@ export class Postgres implements Integration {
60
61
} ) ;
61
62
}
62
63
63
- return ( orig . call ( this , config , values ) as Promise < unknown > ) . then ( ( res : unknown ) => {
64
- span ?. finish ( ) ;
65
- return res ;
66
- } ) ;
64
+ const rv = typeof values !== 'undefined' ? orig . call ( this , config , values ) : orig . call ( this , config ) ;
65
+
66
+ if ( isThenable ( rv ) ) {
67
+ return ( rv as Promise < unknown > ) . then ( ( res : unknown ) => {
68
+ span ?. finish ( ) ;
69
+ return res ;
70
+ } ) ;
71
+ }
72
+
73
+ span ?. finish ( ) ;
74
+ return rv ;
67
75
} ;
68
76
} ) ;
69
77
}
0 commit comments