Skip to content

Commit

Permalink
chore(otel-node): fix test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
david-luna committed Jan 9, 2025
1 parent 70e8756 commit 0682094
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
14 changes: 9 additions & 5 deletions packages/opentelemetry-node/test/fixtures/use-mysql2.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,24 @@
// Usage: node -r @elastic/opentelemetry-node use-mysql2.js

const otel = require('@opentelemetry/api');
var mysql2 = require('mysql2/promise');
var mysql2 = require('mysql2');

const host = process.env.MYSQL_HOST;
const user = process.env.MYSQL_USER || 'root';
const database = process.env.MYSQL_DATABASE || 'mysql';

async function main() {
const connection = await mysql2.createConnection({
const connection = mysql2.createConnection({
host, user, database

Check failure on line 31 in packages/opentelemetry-node/test/fixtures/use-mysql2.js

View workflow job for this annotation

GitHub Actions / lint

Replace `·user,·database` with `⏎········user,⏎········database,`
});
const [ result ] = await connection.query('SELECT 1+1 as solution');
const query = connection.query('SELECT 1+1 as solution');

Check failure on line 33 in packages/opentelemetry-node/test/fixtures/use-mysql2.js

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`

console.log('Mysql query result', result);
await connection.end();

query.on('result', (result) => {
console.log('MySQL result', result)

Check failure on line 37 in packages/opentelemetry-node/test/fixtures/use-mysql2.js

View workflow job for this annotation

GitHub Actions / lint

Insert `;`
});
await new Promise((res) => query.on('end', res));

Check failure on line 39 in packages/opentelemetry-node/test/fixtures/use-mysql2.js

View workflow job for this annotation

GitHub Actions / lint

Promise constructor parameters must be named to match "^_?resolve$"
await new Promise((res) => connection.end(res));

Check failure on line 40 in packages/opentelemetry-node/test/fixtures/use-mysql2.js

View workflow job for this annotation

GitHub Actions / lint

Promise constructor parameters must be named to match "^_?resolve$"
}

const tracer = otel.trace.getTracer('test');
Expand Down
24 changes: 7 additions & 17 deletions packages/opentelemetry-node/test/instr-mysql2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

// Test that 'mysql' instrumentation generates the telemetry we expect.
// Test that 'mysql2' instrumentation generates the telemetry we expect.

const test = require('tape');
const {filterOutDnsNetSpans, runTestFixtures} = require('./testutils');
Expand All @@ -41,13 +41,12 @@ const testFixtures = [
// verbose: true,
checkTelemetry: (t, col) => {
// We expect spans like this
// ------ trace 790a66 (4 spans) ------
// span bd069a "manual-parent-span" (5.4ms, SPAN_KIND_INTERNAL)
// +13ms `- span 1e5ee2 "mongodb.insert" (1.4ms, SPAN_KIND_CLIENT)
// +3ms `- span 3d4723 "mongodb.delete" (0.6ms, SPAN_KIND_CLIENT)
// +1ms `- span 1c1373 "mongodb.endSessions" (0.3ms, SPAN_KIND_CLIENT)
// ------ trace bc3ada (3 spans) ------
// span 8ef53e "manual-parent-span" (21.7ms, SPAN_KIND_INTERNAL)
// +1ms `- span 715182 "tcp.connect" (9.4ms, SPAN_KIND_INTERNAL)
// +2ms `- span 430253 "SELECT" (18.2ms, SPAN_KIND_CLIENT)
const spans = filterOutDnsNetSpans(col.sortedSpans);
t.equal(spans.length, 4);
t.equal(spans.length, 2);

t.equal(spans[0].name, 'manual-parent-span');
t.equal(spans[0].kind, 'SPAN_KIND_INTERNAL');
Expand All @@ -56,19 +55,10 @@ const testFixtures = [
spans[1].scope.name,
'@opentelemetry/instrumentation-mysql2'
);
t.equal(spans[1].name, 'mongodb.insert');
t.equal(spans[1].name, 'SELECT');
t.equal(spans[1].kind, 'SPAN_KIND_CLIENT');
t.equal(spans[1].traceId, spans[0].traceId, 'same trace');
t.equal(spans[1].parentSpanId, spans[0].spanId);

// t.equal(
// spans[2].scope.name,
// '@opentelemetry/instrumentation-mysql2'
// );
// t.equal(spans[2].name, 'mongodb.delete');
// t.equal(spans[2].kind, 'SPAN_KIND_CLIENT');
// t.equal(spans[2].traceId, spans[0].traceId, 'same trace');
// t.equal(spans[2].parentSpanId, spans[0].spanId);
},
},
];
Expand Down

0 comments on commit 0682094

Please sign in to comment.