Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(instr-mysql2): Fix mysql2 instrumentation connection prototype #2578

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@types/mocha": "7.0.2",
"@types/node": "18.18.14",
"@types/semver": "7.5.8",
"mysql2": "3.11.3",
"mysql2": "3.11.5",
"nyc": "15.1.0",
"rimraf": "5.0.10",
"semver": "7.6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@
'mysql2',
['>=1.4.2 <4'],
(moduleExports: any) => {
const ConnectionPrototype: mysqlTypes.Connection =
moduleExports.Connection.prototype;
const ConnectionPrototype =
this._getConnectionPrototype(moduleExports);

if (isWrapped(ConnectionPrototype.query)) {
this._unwrap(ConnectionPrototype, 'query');
}
Expand All @@ -79,8 +80,8 @@
},
(moduleExports: any) => {
if (moduleExports === undefined) return;
const ConnectionPrototype: mysqlTypes.Connection =
moduleExports.Connection.prototype;
const ConnectionPrototype =
this._getConnectionPrototype(moduleExports);
this._unwrap(ConnectionPrototype, 'query');
this._unwrap(ConnectionPrototype, 'execute');
}
Expand Down Expand Up @@ -210,4 +211,16 @@
};
};
}

private _getConnectionPrototype(moduleExports: any): mysqlTypes.Connection {
const baseClass = Object.getPrototypeOf(moduleExports.Connection);

// return the base class prototype if it has the method
// we need to patch ([email protected]+)
if (typeof baseClass.prototype?.query === 'function') {
return baseClass.prototype;
}

return moduleExports.Connection.prototype;

Check warning on line 224 in plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts

View check run for this annotation

Codecov / codecov/patch

plugins/node/opentelemetry-instrumentation-mysql2/src/instrumentation.ts#L224

Added line #L224 was not covered by tests
}
}
Loading