Skip to content

Commit 4190e62

Browse files
feat(instrumentation-aws-lambda): support mjs handlers
1 parent ff40cc8 commit 4190e62

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,11 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
116116
// Lambda loads user function using an absolute path.
117117
let filename = path.resolve(taskRoot, moduleRoot, module);
118118
if (!filename.endsWith('.js')) {
119-
// its impossible to know in advance if the user has a cjs or js file.
120-
// check that the .js file exists otherwise fallback to next known possibility
121-
try {
122-
fs.statSync(`${filename}.js`);
123-
filename += '.js';
124-
} catch (e) {
125-
// fallback to .cjs
126-
filename += '.cjs';
127-
}
119+
// its impossible to know in advance if the user has a cjs, mjs or js file.
120+
// check that the .js file exists otherwise fallback to next known possibilities
121+
if (fs.existsSync(`${filename}.js`)) filename += '.js';
122+
else if (fs.existsSync(`${filename}.mjs`)) filename += '.mjs';
123+
else filename += '.cjs';
128124
}
129125

130126
diag.debug('Instrumenting lambda handler', {

0 commit comments

Comments
 (0)