Skip to content

Commit

Permalink
fixup! fix(instrumentation-mysql2)!: do not include parameterized val…
Browse files Browse the repository at this point in the history
…ues to db.statement span attribute (#1758)
  • Loading branch information
macno committed Dec 7, 2024
1 parent ee6f9b6 commit 6cf79ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
}
span.end();
});

if (typeof arguments[arguments.length - 1] !== 'function') {
function findCallback(_arguments: IArguments) {
for (let i = 0; i < _arguments.length; i++) {
if (typeof _arguments[i] === 'function') {
return i;
}
}
return -1;
}
const cb = findCallback(arguments);
if (cb < 0) {
if (typeof (query as any).onResult === 'function') {
thisPlugin._wrap(
query as any,
Expand All @@ -182,7 +190,7 @@ export class MySQL2Instrumentation extends InstrumentationBase<MySQL2Instrumenta
} else {
thisPlugin._wrap(
arguments,
arguments.length - 1,
cb,
thisPlugin._patchCallbackQuery(endSpan)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,27 @@ describe('mysql2', () => {
});
});

it('should intercept pool.query(text: options, callback, null)', done => {
const span = provider.getTracer('default').startSpan('test span');
context.with(trace.setSpan(context.active(), span), () => {
const sql = 'SELECT 1+1 as solution';
// @ts-ignore
pool.query(
{ sql },
(err, res: mysqlTypes.RowDataPacket[]) => {
assert.ifError(err);
assert.ok(res);
assert.strictEqual(res[0].solution, 2);
const spans = memoryExporter.getFinishedSpans();
assert.strictEqual(spans.length, 1);
assertSpan(spans[0], sql);
done();
},
null
);
});
});

it('should intercept pool.query(text: string, values: [], callback)', done => {
const span = provider.getTracer('default').startSpan('test span');
context.with(trace.setSpan(context.active(), span), () => {
Expand Down

0 comments on commit 6cf79ef

Please sign in to comment.