Skip to content

Commit 3eda55b

Browse files
committed
Remove dataStream.once span nesting
1 parent 66c5e9a commit 3eda55b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

observability-test/database.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,11 +1878,14 @@ describe('Database', () => {
18781878
.on('error', err => {
18791879
assert.fail(err);
18801880
})
1881-
.on('end', () => {
1881+
.on('end', async () => {
18821882
assert.strictEqual(endStub.callCount, 1);
18831883
assert.strictEqual(endStub2.callCount, 1);
18841884
assert.strictEqual(rows, 1);
18851885

1886+
await provider.forceFlush();
1887+
await traceExporter.forceFlush();
1888+
18861889
const spans = traceExporter.getFinishedSpans();
18871890
assert.strictEqual(spans.length, 2, 'Exactly 1 span expected');
18881891
withAllSpansHaveDBName(spans);
@@ -1907,35 +1910,35 @@ describe('Database', () => {
19071910
);
19081911

19091912
// Ensure that the span actually produced an error that was recorded.
1910-
const secondSpan = spans[1];
1911-
assert.strictEqual(
1913+
const lastSpan = spans[0];
1914+
assert.deepStrictEqual(
19121915
SpanStatusCode.ERROR,
1913-
secondSpan.status.code,
1916+
lastSpan.status.code,
19141917
'Expected an ERROR span status'
19151918
);
1916-
assert.strictEqual(
1919+
assert.deepStrictEqual(
19171920
'Session not found',
1918-
secondSpan.status.message,
1921+
lastSpan.status.message,
19191922
'Mismatched span status message'
19201923
);
19211924

19221925
// Ensure that the final span that got retries did not error.
1923-
const firstSpan = spans[0];
1924-
assert.strictEqual(
1926+
const firstSpan = spans[1];
1927+
assert.deepStrictEqual(
19251928
SpanStatusCode.UNSET,
19261929
firstSpan.status.code,
1927-
'Unexpected an span status code'
1930+
'Unexpected span status code'
19281931
);
1929-
assert.strictEqual(
1932+
assert.deepStrictEqual(
19301933
undefined,
19311934
firstSpan.status.message,
19321935
'Unexpected span status message'
19331936
);
19341937

19351938
const expectedEventNames = [
1936-
'Using Session',
19371939
'Using Session',
19381940
'No session available',
1941+
'Using Session',
19391942
];
19401943
assert.deepStrictEqual(
19411944
actualEventNames,

src/database.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,6 @@ class Database extends common.GrpcServiceObject {
856856
callback!(err as ServiceError, null, undefined);
857857
return;
858858
}
859-
860859
const transaction = this.batchTransaction(
861860
{session: session!},
862861
options
@@ -3088,11 +3087,9 @@ class Database extends common.GrpcServiceObject {
30883087
// Create a new data stream and add it to the end user stream.
30893088
dataStream = this.runStream(query, options);
30903089
dataStream.pipe(proxyStream);
3091-
dataStream.on('end', () => span.end());
3092-
dataStream.on('error', err => {
3093-
setSpanError(span, err);
3094-
span.end();
3095-
});
3090+
// Explicitly invoking span.end() here,
3091+
// instead of inside dataStream.on('error').
3092+
span.end();
30963093
} else {
30973094
proxyStream.destroy(err);
30983095
snapshot.end();

0 commit comments

Comments
 (0)