@@ -90,7 +90,7 @@ function patchOf(poolCluster) {
9090
9191 var resultPool = poolCluster [ baseFcn ] . apply ( poolCluster , args ) ;
9292 return patchObject ( resultPool ) ;
93- }
93+ } ;
9494}
9595
9696function patchGetConnection ( pool ) {
@@ -105,13 +105,13 @@ function patchGetConnection(pool) {
105105 args [ args . length - 1 ] = ( err , connection ) => {
106106 if ( connection ) patchObject ( connection ) ;
107107 return callback ( err , connection ) ;
108- }
108+ } ;
109109 }
110110
111111 var result = pool [ baseFcn ] . apply ( pool , args ) ;
112112 if ( result && result . then instanceof Function ) return result . then ( patchObject ) ;
113113 else return result ;
114- }
114+ } ;
115115}
116116
117117function patchObject ( connection ) {
@@ -208,10 +208,6 @@ function captureOperation(name) {
208208 command = originalOperation . call ( this , sql , args . values , args . callback ) ;
209209
210210 if ( ! args . callback ) {
211- command . on ( 'end' , function ( ) {
212- subsegment . close ( ) ;
213- } ) ;
214-
215211 var errorCapturer = function ( err ) {
216212 subsegment . close ( err ) ;
217213
@@ -222,14 +218,26 @@ function captureOperation(name) {
222218 }
223219 } ;
224220
225- command . on ( events . errorMonitor || 'error' , errorCapturer ) ;
221+ if ( command . then instanceof Function ) {
222+ command . then ( ( ) => {
223+ subsegment . close ( ) ;
224+ } ) ;
225+
226+ command . catch ( errorCapturer ) ;
227+ } else {
228+ command . on ( 'end' , function ( ) {
229+ subsegment . close ( ) ;
230+ } ) ;
231+
232+ command . on ( events . errorMonitor || 'error' , errorCapturer ) ;
233+ }
226234 }
227235
228236 subsegment . addSqlData ( createSqlData ( config , command ) ) ;
229237 subsegment . namespace = 'remote' ;
230238
231239 return command ;
232- }
240+ } ;
233241}
234242
235243function createSqlData ( config , command ) {
0 commit comments