Skip to content

Commit 08fb03c

Browse files
committed
test: improved the tests to check span length
1 parent c19847b commit 08fb03c

File tree

2 files changed

+16
-3
lines changed
  • packages
    • collector/test/tracing/database/mysql
    • core/src/tracing/instrumentation/database

2 files changed

+16
-3
lines changed

packages/collector/test/tracing/database/mysql/test.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function registerSuite(agentControls, driverMode, useExecute) {
4646
env.USE_EXECUTE = 'true';
4747
}
4848

49-
test(env, agentControls);
49+
test(env, agentControls, driverMode);
5050
});
5151

5252
describe('suppressed', function () {
@@ -102,7 +102,7 @@ function registerSuite(agentControls, driverMode, useExecute) {
102102
});
103103
}
104104

105-
function test(env, agentControls) {
105+
function test(env, agentControls, driverMode) {
106106
let controls;
107107

108108
before(async () => {
@@ -139,6 +139,11 @@ function test(env, agentControls) {
139139
.then(() =>
140140
testUtils.retry(() =>
141141
agentControls.getSpans().then(spans => {
142+
// 1 x mysql
143+
// 1 x httpserver
144+
// 1 x otel fs(not included in mysql2/promise)
145+
const expectedSpanCount = driverMode === 'mysql2/promises' ? 2 : 3;
146+
expect(spans.length).to.equal(expectedSpanCount);
142147
const entrySpan = testUtils.expectAtLeastOneMatching(spans, [
143148
span => expect(span.n).to.equal('node.http.server'),
144149
span => expect(span.f.e).to.equal(String(controls.getPid())),
@@ -181,6 +186,9 @@ function test(env, agentControls) {
181186

182187
return testUtils.retry(() =>
183188
agentControls.getSpans().then(spans => {
189+
// 2 x mysql
190+
// 2 x httpserver
191+
expect(spans.length).to.equal(4);
184192
const postEntrySpan = testUtils.expectAtLeastOneMatching(spans, [
185193
span => expect(span.n).to.equal('node.http.server'),
186194
span => expect(span.f.e).to.equal(String(controls.getPid())),
@@ -245,6 +253,11 @@ function test(env, agentControls) {
245253

246254
return testUtils.retry(() =>
247255
agentControls.getSpans().then(spans => {
256+
// 1 x mysql
257+
// 1 x httpserver
258+
// 1 x httpclient
259+
const expectedSpanCount = driverMode === 'mysql2/promises' ? 4 : 3;
260+
expect(spans.length).to.equal(expectedSpanCount);
248261
const postEntrySpan = testUtils.expectAtLeastOneMatching(spans, [
249262
span => expect(span.n).to.equal('node.http.server'),
250263
span => expect(span.f.e).to.equal(String(controls.getPid())),

packages/core/src/tracing/instrumentation/database/mysql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function instrumentMysql2(mysql) {
3232
/**
3333
* In mysql2 version 3.11.5 and later, the internal structure of the `Connection` and `Pool` classes was reorganized.
3434
* Methods like `query` and `execute` were moved into the `BaseConnection` class located in `lib/base/connection.js`,
35-
* and similar changes were applied to the `Pool` class.
35+
* and similar changes were applied to the `Pool` class. See: https://github.com/sidorares/node-mysql2/pull/3081
3636
*
3737
* Prior to v3.11.5, the `Connection` and `Pool` prototypes were directly used for instrumentation.
3838
*/

0 commit comments

Comments
 (0)