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 @@ -97,14 +97,28 @@ export class AwsLambdaInstrumentation extends InstrumentationBase<AwsLambdaInstr
97
97
// Lambda loads user function using an absolute path.
98
98
let filename = path . resolve ( taskRoot , moduleRoot , module ) ;
99
99
if ( ! filename . endsWith ( '.js' ) ) {
100
- // its impossible to know in advance if the user has a cjs or js file.
101
- // check that the .js file exists otherwise fallback to next known possibility
100
+ // It's impossible to know in advance if the user has a js, mjs or cjs file.
101
+ // Check that the .js file exists otherwise fallback to the next known possibilities (.mjs, .cjs).
102
102
try {
103
103
fs . statSync ( `${ filename } .js` ) ;
104
104
filename += '.js' ;
105
105
} catch ( e ) {
106
- // fallback to .cjs
107
- filename += '.cjs' ;
106
+ try {
107
+ fs . statSync ( `${ filename } .mjs` ) ;
108
+ // fallback to .mjs (ESM)
109
+ filename += '.mjs' ;
110
+ } catch ( e2 ) {
111
+ try {
112
+ fs . statSync ( `${ filename } .cjs` ) ;
113
+ // fallback to .cjs (CommonJS)
114
+ filename += '.cjs' ;
115
+ } catch ( e3 ) {
116
+ this . _diag . warn (
117
+ 'No handler file was able to resolved with one of the known extensions for the file' ,
118
+ filename
119
+ ) ;
120
+ }
121
+ }
108
122
}
109
123
}
110
124
You can’t perform that action at this time.
0 commit comments