Skip to content

Commit d5c2464

Browse files
committed
fix: Require mysql.Connection directly through mysql/lib/Connection.js
1 parent 949c724 commit d5c2464

File tree

1 file changed

+6
-12
lines changed
  • packages/tracing/src/integrations

1 file changed

+6
-12
lines changed

packages/tracing/src/integrations/mysql.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { EventProcessor, Integration } from '@sentry/types';
33
import { dynamicRequire, fill, logger } from '@sentry/utils';
44

55
interface MysqlConnection {
6-
end: () => void;
76
prototype: {
87
query: () => void;
98
};
@@ -28,23 +27,18 @@ export class Mysql implements Integration {
2827
let connection: MysqlConnection;
2928

3029
try {
31-
const mysqlModule = dynamicRequire(module, 'mysql') as {
32-
createConnection: (options: unknown) => MysqlConnection;
33-
};
34-
const conn = mysqlModule.createConnection({});
35-
connection = (conn.constructor as unknown) as MysqlConnection;
36-
conn.end();
30+
// Unfortunatelly mysql is using some custom loading system and `Connection` is not exported directly.
31+
connection = dynamicRequire(module, 'mysql/lib/Connection.js');
3732
} catch (e) {
3833
logger.error('Mysql Integration was unable to require `mysql` package.');
3934
return;
4035
}
4136

4237
// The original function will have one of these signatures:
43-
// function (query, callback) => void
44-
// function (query, params, callback) => void
45-
// function (query) => Promise
46-
// function (query, params) => Promise
47-
fill(connection, 'query', function(orig: () => void | Promise<unknown>) {
38+
// function (callback) => void
39+
// function (options, callback) => void
40+
// function (options, values, callback) => void
41+
fill(connection.prototype, 'query', function(orig: () => void) {
4842
return function(this: unknown, options: unknown, values: unknown, callback: unknown) {
4943
const scope = getCurrentHub().getScope();
5044
const transaction = scope?.getTransaction();

0 commit comments

Comments
 (0)