Skip to content

Commit

Permalink
chore: added debug logs mysql (#679)
Browse files Browse the repository at this point in the history
  • Loading branch information
kirrg001 authored Jan 10, 2023
1 parent 0dbd0a2 commit 1ce2736
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/src/tracing/instrumentation/database/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

const shimmer = require('shimmer');

let logger;
logger = require('../../../logger').getLogger('tracing/mysql', newLogger => {
logger = newLogger;
});

const requireHook = require('../../../util/requireHook');
const tracingUtil = require('../../tracingUtil');
const constants = require('../../constants');
Expand All @@ -24,18 +29,21 @@ exports.init = function init() {
};

function instrumentMysql(mysql) {
logger.debug('instrumentMysql');
instrumentConnection(Object.getPrototypeOf(mysql.createConnection({})), false);
instrumentPool(Object.getPrototypeOf(mysql.createPool({})));
}

function instrumentMysql2(mysql) {
logger.debug('instrumentMysql2');
instrumentConnection(mysql.Connection.prototype, true);
if (mysql.Pool) {
instrumentPool(mysql.Pool.prototype);
}
}

function instrumentMysql2WithPromises(mysql) {
logger.debug('instrumentMysql2WithPromises');
// Currently only pooled connections will be instrumented.
instrumentPoolWithPromises(mysql);
}
Expand Down Expand Up @@ -73,6 +81,7 @@ function instrumentPoolWithPromises(mysql) {

function shimQuery(original) {
return function () {
logger.debug('shimQuery');
if (cls.skipExitTracing({ isActive })) {
return original.apply(this, arguments);
}
Expand All @@ -83,6 +92,7 @@ function shimQuery(original) {

function shimExecute(original) {
return function () {
logger.debug('shimExecute');
if (cls.skipExitTracing({ isActive })) {
return original.apply(this, arguments);
}
Expand All @@ -93,6 +103,7 @@ function shimExecute(original) {

function shimPromiseQuery(originalQuery) {
return function () {
logger.debug('shimPromiseQuery');
if (cls.skipExitTracing({ isActive })) {
return originalQuery.apply(this, arguments);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/util/requireHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function patchedModuleLoad(moduleName) {
// we try to grab the module name to being able to patch the target module
// with our instrumentation
if (path.isAbsolute(moduleName)) {
logger.debug('Path is absolute.', moduleName);
// EDGE CASE for ESM: mysql2/promise.js
if (moduleName.indexOf('node_modules/mysql2/promise.js') !== -1) {
moduleName = 'mysql2/promise';
Expand All @@ -76,6 +77,7 @@ function patchedModuleLoad(moduleName) {
}
}
}
logger.debug('Path was transformed.', moduleName);
}

// First attempt to always get the module via the original implementation
Expand Down

0 comments on commit 1ce2736

Please sign in to comment.