File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
plugins/node/opentelemetry-instrumentation-aws-lambda/src Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -117,14 +117,28 @@ export class AwsLambdaInstrumentation extends InstrumentationBase<AwsLambdaInstr
117117 // Lambda loads user function using an absolute path.
118118 let filename = path . resolve ( taskRoot , moduleRoot , module ) ;
119119 if ( ! filename . endsWith ( '.js' ) ) {
120- // its impossible to know in advance if the user has a cjs or js file.
121- // check that the .js file exists otherwise fallback to next known possibility
120+ // Its impossible to know in advance if the user has a js, cjs or mjs file.
121+ // Check that the .js file exists otherwise fallback to the next known possibilities (.cjs, .mjs).
122122 try {
123123 fs . statSync ( `${ filename } .js` ) ;
124124 filename += '.js' ;
125125 } catch ( e ) {
126- // fallback to .cjs
127- filename += '.cjs' ;
126+ try {
127+ fs . statSync ( `${ filename } .cjs` ) ;
128+ // fallback to .cjs (CommonJS)
129+ filename += '.cjs' ;
130+ } catch ( e2 ) {
131+ try {
132+ fs . statSync ( `${ filename } .mjs` ) ;
133+ // fallback to .mjs (ESM)
134+ filename += '.mjs' ;
135+ } catch ( e3 ) {
136+ diag . error (
137+ 'No handler file was able to resolved with one of the known extensions for the file' ,
138+ filename
139+ ) ;
140+ }
141+ }
128142 }
129143 }
130144
You can’t perform that action at this time.
0 commit comments