Skip to content

Commit c19847b

Browse files
committed
fix: handled changes in mysql2 v3.11.5 class structure
1 parent 9abd2c4 commit c19847b

File tree

1 file changed

+20
-3
lines changed
  • packages/core/src/tracing/instrumentation/database

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,26 @@ function instrumentMysql(mysql) {
2929
}
3030

3131
function instrumentMysql2(mysql) {
32-
instrumentConnection(mysql.Connection.prototype, true);
33-
if (mysql.Pool) {
34-
instrumentPool(mysql.Pool.prototype);
32+
/**
33+
* In mysql2 version 3.11.5 and later, the internal structure of the `Connection` and `Pool` classes was reorganized.
34+
* 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.
36+
*
37+
* Prior to v3.11.5, the `Connection` and `Pool` prototypes were directly used for instrumentation.
38+
*/
39+
const connectionPrototype =
40+
Object.getPrototypeOf(mysql.Connection.prototype)?.constructor?.name === 'BaseConnection'
41+
? Object.getPrototypeOf(mysql.Connection.prototype)
42+
: mysql.Connection.prototype;
43+
44+
const poolPrototype =
45+
mysql.Pool && Object.getPrototypeOf(mysql.Pool.prototype)?.constructor?.name === 'BasePool'
46+
? Object.getPrototypeOf(mysql.Pool.prototype)
47+
: mysql.Pool?.prototype;
48+
49+
instrumentConnection(connectionPrototype, true);
50+
if (poolPrototype) {
51+
instrumentPool(poolPrototype);
3552
}
3653
}
3754

0 commit comments

Comments
 (0)