-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(instrumentation-mysql2): instrument connection on 3.11.5 (#2579)
- Loading branch information
1 parent
8bfa21f
commit e674b1b
Showing
5 changed files
with
45 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,3 +146,22 @@ export const once = (fn: Function) => { | |
return fn(...args); | ||
}; | ||
}; | ||
|
||
export function getConnectionPrototypeToInstrument(connection: any) { | ||
const connectionPrototype = connection.prototype; | ||
const basePrototype = Object.getPrototypeOf(connectionPrototype); | ||
|
||
// [email protected] included a refactoring, where most code was moved out of the `Connection` class and into a shared base | ||
// so we need to instrument that instead, see https://github.com/sidorares/node-mysql2/pull/3081 | ||
// This checks if the functions we're instrumenting are there on the base - we cannot use the presence of a base | ||
// prototype since EventEmitter is the base for mysql2@<=3.11.4 | ||
if ( | ||
typeof basePrototype?.query === 'function' && | ||
typeof basePrototype?.execute === 'function' | ||
) { | ||
return basePrototype; | ||
} | ||
|
||
// otherwise instrument the connection directly. | ||
return connectionPrototype; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters