Skip to content

Commit

Permalink
fix(koa): fix instrumentation of ESM-imported koa
Browse files Browse the repository at this point in the history
  • Loading branch information
chentsulin committed Oct 13, 2023
1 parent a8c225d commit 7fc6bef
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export class KoaInstrumentation extends InstrumentationBase<typeof koa> {
return new InstrumentationNodeModuleDefinition<typeof koa>(
'koa',
['^2.0.0'],
moduleExports => {
module => {
const moduleExports =
module[Symbol.toStringTag] === 'Module'
? module.default // ESM
: module; // CommonJS
if (moduleExports == null) {
return moduleExports;
}
Expand All @@ -68,9 +72,13 @@ export class KoaInstrumentation extends InstrumentationBase<typeof koa> {
'use',
this._getKoaUsePatch.bind(this)
);
return moduleExports;
return module;
},
moduleExports => {
module => {
const moduleExports =
module[Symbol.toStringTag] === 'Module'
? module.default // ESM
: module; // CommonJS
api.diag.debug('Unpatching Koa');
if (isWrapped(moduleExports.prototype.use)) {
this._unwrap(moduleExports.prototype, 'use');
Expand Down

0 comments on commit 7fc6bef

Please sign in to comment.