@@ -21,6 +21,8 @@ const api = module.exports = {
21
21
install ( domain , getConnection , opts ) {
22
22
opts = Object . assign ( {
23
23
maxConcurrency : Infinity ,
24
+ onSubsessionStart : noop ,
25
+ onSubsessionFinish : noop ,
24
26
onSessionIdle : noop ,
25
27
onConnectionRequest : noop ,
26
28
onConnectionStart : noop ,
@@ -86,6 +88,8 @@ class Session {
86
88
this . activeConnections = 0
87
89
this . maxConcurrency = opts . maxConcurrency || Infinity
88
90
this . metrics = {
91
+ onSubsessionStart : opts . onSubsessionStart ,
92
+ onSubsessionFinish : opts . onSubsessionFinish ,
89
93
onSessionIdle : opts . onSessionIdle ,
90
94
onConnectionRequest : opts . onConnectionRequest ,
91
95
onConnectionStart : opts . onConnectionStart ,
@@ -239,6 +243,7 @@ function Session$RunWrapped (parent,
239
243
return getConnPair . then ( pair => {
240
244
const subdomain = domain . create ( )
241
245
const session = createSession ( pair )
246
+ parent . metrics . onSubsessionStart ( parent , session )
242
247
DOMAIN_TO_SESSION . set ( subdomain , session )
243
248
244
249
const runBefore = new Promise ( ( resolve , reject ) => {
@@ -273,7 +278,13 @@ function Session$RunWrapped (parent,
273
278
err => err ? reject ( err ) : resolve ( )
274
279
)
275
280
} )
276
- } )
281
+ } ) . then (
282
+ ( ) => parent . metrics . onSubsessionFinish ( parent , session ) ,
283
+ err => {
284
+ parent . metrics . onSubsessionFinish ( parent , session )
285
+ throw err
286
+ }
287
+ )
277
288
return runCommitStep . return ( getResult )
278
289
} )
279
290
} )
0 commit comments