From 4190e62656bd227262773038aa346e49bb0072ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Th=C3=A9riault?= Date: Wed, 6 Mar 2024 14:15:28 -0800 Subject: [PATCH] feat(instrumentation-aws-lambda): support mjs handlers --- .../src/instrumentation.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts index 0b85377d1d..5ba3aa7786 100644 --- a/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts @@ -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', {