@@ -3363,46 +3363,54 @@ class Database extends common.GrpcServiceObject {
33633363
33643364 let sessionId = '' ;
33653365 const getSession = this . pool_ . getSession . bind ( this . pool_ ) ;
3366- const span = getActiveOrNoopSpan ( ) ;
3367- // Loop to retry 'Session not found' errors.
3368- // (and yes, we like while (true) more than for (;;) here)
3369- // eslint-disable-next-line no-constant-condition
3370- while ( true ) {
3371- try {
3372- const [ session , transaction ] = await promisify ( getSession ) ( ) ;
3373- transaction . requestOptions = Object . assign (
3374- transaction . requestOptions || { } ,
3375- options . requestOptions
3376- ) ;
3377- if ( options . optimisticLock ) {
3378- transaction . useOptimisticLock ( ) ;
3379- }
3380- if ( options . excludeTxnFromChangeStreams ) {
3381- transaction . excludeTxnFromChangeStreams ( ) ;
3382- }
3383- sessionId = session ?. id ;
3384- span . addEvent ( 'Using Session' , { 'session.id' : sessionId } ) ;
3385- const runner = new AsyncTransactionRunner < T > (
3386- session ,
3387- transaction ,
3388- runFn ,
3389- options
3390- ) ;
3391-
3392- try {
3393- return await runner . run ( ) ;
3394- } finally {
3395- this . pool_ . release ( session ) ;
3396- }
3397- } catch ( e ) {
3398- if ( ! isSessionNotFoundError ( e as ServiceError ) ) {
3399- span . addEvent ( 'No session available' , {
3400- 'session.id' : sessionId ,
3401- } ) ;
3402- throw e ;
3366+ return startTrace (
3367+ 'Database.runTransactionAsync' ,
3368+ this . _traceConfig ,
3369+ async span => {
3370+ // Loop to retry 'Session not found' errors.
3371+ // (and yes, we like while (true) more than for (;;) here)
3372+ // eslint-disable-next-line no-constant-condition
3373+ while ( true ) {
3374+ try {
3375+ const [ session , transaction ] = await promisify ( getSession ) ( ) ;
3376+ transaction . requestOptions = Object . assign (
3377+ transaction . requestOptions || { } ,
3378+ options . requestOptions
3379+ ) ;
3380+ if ( options . optimisticLock ) {
3381+ transaction . useOptimisticLock ( ) ;
3382+ }
3383+ if ( options . excludeTxnFromChangeStreams ) {
3384+ transaction . excludeTxnFromChangeStreams ( ) ;
3385+ }
3386+ sessionId = session ?. id ;
3387+ span . addEvent ( 'Using Session' , { 'session.id' : sessionId } ) ;
3388+ const runner = new AsyncTransactionRunner < T > (
3389+ session ,
3390+ transaction ,
3391+ runFn ,
3392+ options
3393+ ) ;
3394+
3395+ try {
3396+ const result = await runner . run ( ) ;
3397+ span . end ( ) ;
3398+ return result ;
3399+ } finally {
3400+ this . pool_ . release ( session ) ;
3401+ }
3402+ } catch ( e ) {
3403+ if ( ! isSessionNotFoundError ( e as ServiceError ) ) {
3404+ span . addEvent ( 'No session available' , {
3405+ 'session.id' : sessionId ,
3406+ } ) ;
3407+ span . end ( ) ;
3408+ throw e ;
3409+ }
3410+ }
34033411 }
34043412 }
3405- }
3413+ ) ;
34063414 }
34073415
34083416 /**
0 commit comments