Skip to content

Commit

Permalink
feat(instrumentation-aws-lambda): support mjs handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael-theriault-swi committed Mar 6, 2024
1 parent ff40cc8 commit 4190e62
Showing 1 changed file with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,11 @@ export class AwsLambdaInstrumentation extends InstrumentationBase {
// Lambda loads user function using an absolute path.
let filename = path.resolve(taskRoot, moduleRoot, module);
if (!filename.endsWith('.js')) {
// its impossible to know in advance if the user has a cjs or js file.
// check that the .js file exists otherwise fallback to next known possibility
try {
fs.statSync(`${filename}.js`);
filename += '.js';
} catch (e) {
// fallback to .cjs
filename += '.cjs';
}
// its impossible to know in advance if the user has a cjs, mjs or js file.
// check that the .js file exists otherwise fallback to next known possibilities
if (fs.existsSync(`${filename}.js`)) filename += '.js';
else if (fs.existsSync(`${filename}.mjs`)) filename += '.mjs';
else filename += '.cjs';
}

diag.debug('Instrumenting lambda handler', {
Expand Down

0 comments on commit 4190e62

Please sign in to comment.