Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instrumentation-aws-lambda): take care of ESM based (.mjs) handlers #2508

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,28 @@
// 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
// Its impossible to know in advance if the user has a js, cjs or mjs file.
trentm marked this conversation as resolved.
Show resolved Hide resolved
// Check that the .js file exists otherwise fallback to the next known possibilities (.cjs, .mjs).
trentm marked this conversation as resolved.
Show resolved Hide resolved
try {
fs.statSync(`${filename}.js`);
filename += '.js';
} catch (e) {
// fallback to .cjs
filename += '.cjs';
try {
fs.statSync(`${filename}.cjs`);
// fallback to .cjs (CommonJS)
filename += '.cjs';
} catch (e2) {
try {
fs.statSync(`${filename}.mjs`);

Check warning on line 112 in plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts

View check run for this annotation

Codecov / codecov/patch

plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts#L111-L112

Added lines #L111 - L112 were not covered by tests
// fallback to .mjs (ESM)
filename += '.mjs';

Check warning on line 114 in plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L114 was not covered by tests
} catch (e3) {
diag.error(

Check warning on line 116 in plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts

View check run for this annotation

Codecov / codecov/patch

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

Added line #L116 was not covered by tests
trentm marked this conversation as resolved.
Show resolved Hide resolved
'No handler file was able to resolved with one of the known extensions for the file',
filename
);
}
}
}
}

Expand Down