Skip to content

Commit 7fc6bef

Browse files
committed
fix(koa): fix instrumentation of ESM-imported koa
1 parent a8c225d commit 7fc6bef

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

plugins/node/opentelemetry-instrumentation-koa/src/instrumentation.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ export class KoaInstrumentation extends InstrumentationBase<typeof koa> {
5555
return new InstrumentationNodeModuleDefinition<typeof koa>(
5656
'koa',
5757
['^2.0.0'],
58-
moduleExports => {
58+
module => {
59+
const moduleExports =
60+
module[Symbol.toStringTag] === 'Module'
61+
? module.default // ESM
62+
: module; // CommonJS
5963
if (moduleExports == null) {
6064
return moduleExports;
6165
}
@@ -68,9 +72,13 @@ export class KoaInstrumentation extends InstrumentationBase<typeof koa> {
6872
'use',
6973
this._getKoaUsePatch.bind(this)
7074
);
71-
return moduleExports;
75+
return module;
7276
},
73-
moduleExports => {
77+
module => {
78+
const moduleExports =
79+
module[Symbol.toStringTag] === 'Module'
80+
? module.default // ESM
81+
: module; // CommonJS
7482
api.diag.debug('Unpatching Koa');
7583
if (isWrapped(moduleExports.prototype.use)) {
7684
this._unwrap(moduleExports.prototype, 'use');

0 commit comments

Comments
 (0)