Skip to content

Commit edaee77

Browse files
authored
fix: pass the Span correctly (#2332)
#2320
1 parent 88711de commit edaee77

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

observability-test/spanner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ describe('ObservabilityOptions injection and propagation', async () => {
652652
...cacheSessionEvents,
653653
'Using Session',
654654
'Starting stream',
655+
'Transaction Creation Done',
655656
];
656657
assert.deepStrictEqual(
657658
actualEventNames,
@@ -1729,8 +1730,8 @@ describe('Traces for ExecuteStream broken stream retries', () => {
17291730
const expectedEventNames = [
17301731
...batchCreateSessionsEvents,
17311732
'Starting stream',
1732-
...waitingSessionsEvents,
17331733
'Transaction Creation Done',
1734+
...waitingSessionsEvents,
17341735
];
17351736
assert.deepStrictEqual(
17361737
actualEventNames,

src/transaction.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
} from './partial-result-stream';
3434
import {Session} from './session';
3535
import {Key} from './table';
36-
import {getActiveOrNoopSpan} from './instrument';
36+
import {Span} from './instrument';
3737
import {google as spannerClient} from '../protos/protos';
3838
import {
3939
NormalCallback,
@@ -499,7 +499,7 @@ export class Snapshot extends EventEmitter {
499499
setSpanError(span, err);
500500
} else {
501501
this._updatePrecommitToken(resp);
502-
this._update(resp);
502+
this._update(resp, span);
503503
}
504504
span.end();
505505
callback!(err, resp);
@@ -802,7 +802,7 @@ export class Snapshot extends EventEmitter {
802802
?.on('response', response => {
803803
this._updatePrecommitToken(response);
804804
if (response.metadata && response.metadata!.transaction && !this.id) {
805-
this._update(response.metadata!.transaction);
805+
this._update(response.metadata!.transaction, span);
806806
}
807807
})
808808
.on('error', err => {
@@ -1159,7 +1159,7 @@ export class Snapshot extends EventEmitter {
11591159
if (response.metadata) {
11601160
metadata = response.metadata;
11611161
if (metadata.transaction && !this.id) {
1162-
this._update(metadata.transaction);
1162+
this._update(metadata.transaction, span);
11631163
}
11641164
}
11651165
})
@@ -1406,7 +1406,7 @@ export class Snapshot extends EventEmitter {
14061406
.on('response', response => {
14071407
this._updatePrecommitToken(response);
14081408
if (response.metadata && response.metadata!.transaction && !this.id) {
1409-
this._update(response.metadata!.transaction);
1409+
this._update(response.metadata!.transaction, span);
14101410
}
14111411
})
14121412
.on('error', err => {
@@ -1617,13 +1617,15 @@ export class Snapshot extends EventEmitter {
16171617
*
16181618
* @param {spannerClient.spanner.v1.ITransaction} resp Response object.
16191619
*/
1620-
protected _update(resp: spannerClient.spanner.v1.ITransaction): void {
1620+
protected _update(
1621+
resp: spannerClient.spanner.v1.ITransaction,
1622+
span: Span,
1623+
): void {
16211624
const {id, readTimestamp} = resp;
16221625

16231626
this.id = id!;
16241627
this.metadata = resp;
16251628

1626-
const span = getActiveOrNoopSpan();
16271629
span.addEvent('Transaction Creation Done', {id: this.id.toString()});
16281630

16291631
if (readTimestamp) {
@@ -2071,7 +2073,7 @@ export class Transaction extends Dml {
20712073
const {resultSets, status} = resp;
20722074
for (const resultSet of resultSets) {
20732075
if (!this.id && resultSet.metadata?.transaction) {
2074-
this._update(resultSet.metadata.transaction);
2076+
this._update(resultSet.metadata.transaction, span);
20752077
}
20762078
}
20772079
const rowCounts: number[] = resultSets.map(({stats}) => {

0 commit comments

Comments
 (0)