Skip to content

Commit

Permalink
fix(pg): fix instrumentation of ESM-imported pg (#1701)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Pichler <[email protected]>
  • Loading branch information
trentm and pichlermarc authored Oct 17, 2023
1 parent 7b457cd commit 2502e18
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ export class PgInstrumentation extends InstrumentationBase {
const modulePG = new InstrumentationNodeModuleDefinition<typeof pgTypes>(
'pg',
['8.*'],
moduleExports => {
(module: any) => {
const moduleExports: typeof pgTypes =
module[Symbol.toStringTag] === 'Module'
? module.default // ESM
: module; // CommonJS
if (isWrapped(moduleExports.Client.prototype.query)) {
this._unwrap(moduleExports.Client.prototype, 'query');
}
Expand All @@ -87,9 +91,13 @@ export class PgInstrumentation extends InstrumentationBase {
this._getClientConnectPatch() as any
);

return moduleExports;
return module;
},
moduleExports => {
(module: any) => {
const moduleExports: typeof pgTypes =
module[Symbol.toStringTag] === 'Module'
? module.default // ESM
: module; // CommonJS
if (isWrapped(moduleExports.Client.prototype.query)) {
this._unwrap(moduleExports.Client.prototype, 'query');
}
Expand Down

0 comments on commit 2502e18

Please sign in to comment.