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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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 @@ -117,14 +117,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.
// Check that the .js file exists otherwise fallback to the next known possibilities (.cjs, .mjs).
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 132 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#L131-L132

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

Check warning on line 134 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#L134

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

Check warning on line 136 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#L136

Added line #L136 was not covered by tests
'No handler file was able to resolved with one of the known extensions for the file',
filename
);
}
}
}
}

Expand Down
Loading