feat(observability): fix bugs found from product review + negative cases#2158
Conversation
62bf905 to
1b7d8b6
Compare
| if (err) { | ||
| setSpanError(span, err!); | ||
| } | ||
| await runner.run().then(release, async err => { |
There was a problem hiding this comment.
we are already doing .then() on runner.run(), why do we then need to await here?
There was a problem hiding this comment.
@odeke-em it will work even if we don't await on runner.run(). please check and remove the await
| (err as grpc.ServiceError).code === grpc.status.ABORTED | ||
| ) | ||
| ) { | ||
| span.addEvent('Transaction Aborted, retrying begin', { |
There was a problem hiding this comment.
This code block is for the non Aborted errors. Change Transaction threw error, retrying with explicit begin
| 'session.id': session?.id, | ||
| }); | ||
| this.runTransaction(options, runFn!); | ||
| await this.runTransaction(options, runFn!); |
There was a problem hiding this comment.
Why have we added await on this.runTransaction. This does not return a promise nor its a async method.
| } | ||
|
|
||
| if (err) { | ||
| await runFn!(err as grpc.ServiceError); |
| }); | ||
| release(); | ||
| this.runTransaction(options, runFn!); | ||
| await this.runTransaction(options, runFn!); |
There was a problem hiding this comment.
again why async here?
|
|
||
| try { | ||
| const result = await runner.run(); | ||
| span.end(); |
There was a problem hiding this comment.
span.end() should be done in finally block.
There was a problem hiding this comment.
Not really, on an exception this code retries in the while loop above so that's not correct to end it in the finally block. It should be ended only on success.
| ) | ||
| ) { | ||
| this.begin(); | ||
| span.addEvent('Stream broken. Safe to retry', { |
There was a problem hiding this comment.
remove these two spans for stream broken. We are not retrying broken stream here , that is happening in partial-result-stream class. https://github.com/googleapis/nodejs-spanner/blob/main/src/partial-result-stream.ts#L558-L586
Maybe lets skip these two spans for now and move on.
| ) | ||
| ) { | ||
| this.begin(); | ||
| span.addEvent('Stream broken. Safe to retry', { |
There was a problem hiding this comment.
same here. remove these events
| callback(err, resp); | ||
| }); | ||
| }, callback); | ||
| try { |
There was a problem hiding this comment.
no change is required here. As we are doing ".then" on begin call.
91c5281 to
508243f
Compare
7bdc173 to
a3589e5
Compare
Extracted out of PR googleapis#2158, this change traces Database.runTransactionAsync. However, testing isn't effective because of bugs such as googleapis#2166.
Extracted out of PR googleapis#2158, this change traces Database.runTransactionAsync. However, testing isn't effective because of bugs such as googleapis#2166.
Extracted out of PR googleapis#2158, this change traces Database.runTransactionAsync. Updates googleapis#2079
e0e31f5 to
13bc9f5
Compare
3fb5164 to
03a6298
Compare
|
@alkatrivedi kindly help me run the bots. |
|
Kind ping @alkatrivedi to run the bots. |
|
Kind ping @harshachinta @alkatrivedi @surbhigarg92 to run the bots as I need rapid debugging but the time in-between is too long. |
| setSpanErrorAndException(span, e as Error); | ||
| this.emit('error', e); | ||
| } finally { | ||
| if (span.isRecording()) { |
There was a problem hiding this comment.
Please remove span. isRecording
| span.end(); | ||
| callback!(err, snapshot); | ||
| }); | ||
| this.getSnapshot(options, callback!); |
There was a problem hiding this comment.
move span.end() above the callback. We will not see the traces hierarchy in this case which is ok for sessionnotfounderror.
| callback!(err, snapshot); | ||
| }); | ||
| this.getSnapshot(options, callback!); | ||
| // Explicitly requested in code review that this span.end() be |
There was a problem hiding this comment.
Please remove these comments from code
| dataStream = this.runStream(query, options); | ||
| dataStream.pipe(proxyStream); | ||
| // Explicitly invoking span.end() here, | ||
| // instead of inside dataStream.on('error'). | ||
| span.end(); |
There was a problem hiding this comment.
Move span.end() to before we create new datastream
| } | ||
| setImmediate(runFn!, err); | ||
| release(); | ||
| span.end(); |
There was a problem hiding this comment.
remove span.end() once we add it in release method
| options | ||
| ); | ||
| dataStream.pipe(proxyStream); | ||
| span.end(); |
There was a problem hiding this comment.
move this span.end() before creating new stream
| // Retry this method. | ||
| this.writeAtLeastOnce(mutations, options, (err, resp) => { | ||
| if (err) { | ||
| setSpanError(span, err); | ||
| } | ||
| span.end(); | ||
| cb!(err, resp); | ||
| }); |
There was a problem hiding this comment.
We can remove this change and add span.end() before retry
| // TODO: re-examine if this.begin() should still exist and if | ||
| // an await is needed: with await the generated begin span | ||
| // will look wonky and out of order. Please ses |
There was a problem hiding this comment.
Please add a short comment, bug has details
| // TODO: Examine the consequence of not awaiting this method, | ||
| // as the span might appear out of order. | ||
| // Please see https://github.com/googleapis/nodejs-spanner/issues/2170 |
This change adds recording of retry span annotations, catching cases in which exceptions where thrown but spans were not ended while testing out and visually confirming the results.
| .catch(e => { | ||
| setSpanErrorAndException(span, e as Error); | ||
| throw e; | ||
| }); |
There was a problem hiding this comment.
| .catch(e => { | |
| setSpanErrorAndException(span, e as Error); | |
| throw e; | |
| }); | |
| .catch(e => { | |
| setSpanErrorAndException(span, e as Error); | |
| span.end(); | |
| throw e; | |
| }); |
This change adds recording of retry span annotations, catching cases in which exceptions where thrown but spans were not ended while testing out and visually confirming the results.