@@ -1131,9 +1131,7 @@ class Database extends common.GrpcServiceObject {
11311131 setSpanErrorAndException ( span , e as Error ) ;
11321132 this . emit ( 'error' , e ) ;
11331133 } finally {
1134- if ( span . isRecording ( ) ) {
1135- span . end ( ) ;
1136- }
1134+ span . end ( ) ;
11371135 }
11381136 } ) ;
11391137 }
@@ -2104,11 +2102,8 @@ class Database extends common.GrpcServiceObject {
21042102 } ) ;
21052103 session ! . lastError = err ;
21062104 this . pool_ . release ( session ! ) ;
2107- this . getSnapshot ( options , callback ! ) ;
2108- // Explicitly requested in code review that this span.end() be
2109- // moved out of this.getSnapshot, and that there will a later refactor,
2110- // similar to https://github.com/googleapis/nodejs-spanner/issues/2159
21112105 span . end ( ) ;
2106+ this . getSnapshot ( options , callback ! ) ;
21122107 } else {
21132108 span . addEvent ( 'Using Session' , { 'session.id' : session ?. id } ) ;
21142109 this . pool_ . release ( session ! ) ;
@@ -3084,12 +3079,10 @@ class Database extends common.GrpcServiceObject {
30843079 dataStream . removeListener ( 'end' , endListener ) ;
30853080 dataStream . end ( ) ;
30863081 snapshot . end ( ) ;
3082+ span . end ( ) ;
30873083 // Create a new data stream and add it to the end user stream.
30883084 dataStream = this . runStream ( query , options ) ;
30893085 dataStream . pipe ( proxyStream ) ;
3090- // Explicitly invoking span.end() here,
3091- // instead of inside dataStream.on('error').
3092- span . end ( ) ;
30933086 } else {
30943087 proxyStream . destroy ( err ) ;
30953088 snapshot . end ( ) ;
@@ -3219,26 +3212,6 @@ class Database extends common.GrpcServiceObject {
32193212 ? ( optionsOrRunFn as RunTransactionOptions )
32203213 : { } ;
32213214
3222- const retry = ( span : Span ) => {
3223- this . runTransaction ( options , ( err , txn ) => {
3224- if ( err ) {
3225- setSpanError ( span , err ) ;
3226- span . end ( ) ;
3227- runFn ! ( err , null ) ;
3228- return ;
3229- }
3230-
3231- txn ! . once ( 'end' , ( ) => {
3232- span . end ( ) ;
3233- } ) ;
3234- txn ! . once ( 'error' , err => {
3235- setSpanError ( span , err ! ) ;
3236- span . end ( ) ;
3237- } ) ;
3238- runFn ! ( null , txn ! ) ;
3239- } ) ;
3240- } ;
3241-
32423215 startTrace ( 'Database.runTransaction' , this . _traceConfig , span => {
32433216 this . pool_ . getSession ( ( err , session ?, transaction ?) => {
32443217 if ( err ) {
@@ -3249,7 +3222,8 @@ class Database extends common.GrpcServiceObject {
32493222 span . addEvent ( 'No session available' , {
32503223 'session.id' : session ?. id ,
32513224 } ) ;
3252- retry ( span ) ;
3225+ span . end ( ) ;
3226+ this . runTransaction ( options , runFn ! ) ;
32533227 return ;
32543228 }
32553229
@@ -3267,19 +3241,9 @@ class Database extends common.GrpcServiceObject {
32673241 transaction ! . excludeTxnFromChangeStreams ( ) ;
32683242 }
32693243
3270- // Our span should only be ended if the
3271- // transaction either errored or was ended.
3272- transaction ! . once ( 'error' , err => {
3273- setSpanError ( span , err ! ) ;
3274- span . end ( ) ;
3275- } ) ;
3276-
3277- transaction ! . once ( 'end' , ( ) => {
3278- span . end ( ) ;
3279- } ) ;
3280-
32813244 const release = ( ) => {
32823245 this . pool_ . release ( session ! ) ;
3246+ span . end ( ) ;
32833247 } ;
32843248
32853249 const runner = new TransactionRunner (
@@ -3289,21 +3253,26 @@ class Database extends common.GrpcServiceObject {
32893253 options
32903254 ) ;
32913255
3292- runner . run ( ) . then ( release , err => {
3293- setSpanError ( span , err ) ;
3256+ runner
3257+ . run ( )
3258+ . then ( release , err => {
3259+ setSpanError ( span , err ) ;
32943260
3295- if ( isSessionNotFoundError ( err ) ) {
3296- span . addEvent ( 'No session available' , {
3297- 'session.id' : session ?. id ,
3298- } ) ;
3299- release ( ) ;
3300- retry ( span ) ;
3301- } else {
3302- setImmediate ( runFn ! , err ) ;
3303- release ( ) ;
3304- span . end ( ) ;
3305- }
3306- } ) ;
3261+ if ( isSessionNotFoundError ( err ) ) {
3262+ span . addEvent ( 'No session available' , {
3263+ 'session.id' : session ?. id ,
3264+ } ) ;
3265+ release ( ) ;
3266+ this . runTransaction ( options , runFn ! ) ;
3267+ } else {
3268+ release ( ) ;
3269+ setImmediate ( runFn ! , err ) ;
3270+ }
3271+ } )
3272+ . catch ( e => {
3273+ setSpanErrorAndException ( span , e as Error ) ;
3274+ throw e ;
3275+ } ) ;
33073276 } ) ;
33083277 } ) ;
33093278 }
@@ -3557,13 +3526,13 @@ class Database extends common.GrpcServiceObject {
35573526 // Remove the current data stream from the end user stream.
35583527 dataStream . unpipe ( proxyStream ) ;
35593528 dataStream . end ( ) ;
3529+ span . end ( ) ;
35603530 // Create a new stream and add it to the end user stream.
35613531 dataStream = this . batchWriteAtLeastOnce (
35623532 mutationGroups ,
35633533 options
35643534 ) ;
35653535 dataStream . pipe ( proxyStream ) ;
3566- span . end ( ) ;
35673536 } else {
35683537 span . end ( ) ;
35693538 proxyStream . destroy ( err ) ;
@@ -3662,14 +3631,8 @@ class Database extends common.GrpcServiceObject {
36623631 span . addEvent ( 'No session available' , {
36633632 'session.id' : session ?. id ,
36643633 } ) ;
3665- // Retry this method.
3666- this . writeAtLeastOnce ( mutations , options , ( err , resp ) => {
3667- if ( err ) {
3668- setSpanError ( span , err ) ;
3669- }
3670- span . end ( ) ;
3671- cb ! ( err , resp ) ;
3672- } ) ;
3634+ span . end ( ) ;
3635+ this . writeAtLeastOnce ( mutations , options , cb ! ) ;
36733636 return ;
36743637 }
36753638 if ( err ) {
0 commit comments