-
Notifications
You must be signed in to change notification settings - Fork 619
feat(instrumentation-aws-lambda): add runtime-aware handler support for Node.js 24 compatibility #3255
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): add runtime-aware handler support for Node.js 24 compatibility #3255
Conversation
BREAKING CHANGE: Removed support for callback-based Lambda handlers. Only Promise-based handlers (async/await or functions returning Promises) are now supported. This aligns with AWS Lambda's deprecation of callbacks in Node.js 24 runtime. Changes: - Removed Callback import and _wrapCallback method from instrumentation - Updated patchedHandler to only accept (event, context) parameters - Converted all test handlers from callback-based to Promise-based - Updated all tests to use Promise-based handlers directly - Added migration guide in README.md - Documented breaking change in CHANGELOG.md All 50 tests passing.
…ith backward compatibility Added runtime-aware handler support that automatically detects Node.js version from AWS_EXECUTION_ENV and adapts handler signatures accordingly. Node.js 24+ only supports Promise-based handlers, while Node.js 22 and lower support both callback and Promise-based handlers for backward compatibility.
maxday
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @RaphaelManke
I left minor comments, feel free to ignore
- Refactor getNodeRuntimeVersion() to isSupportingCallbacks() returning boolean - Default to false (no callbacks) when AWS_EXECUTION_ENV is not set - Update README example to use ESM syntax for Promise-based handler
| }; | ||
|
|
||
| exports.stringerror = function (event, context, callback) { | ||
| exports.callbackstringerror = async function (event, context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I suppose the "callback" name in this test fixture is a bit out of place now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this is a leftover from an intermediate state. Deleted it as its covered in another test
|
Confirming it's working fine by
was failing before, succeeding with this change |
maxday
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @RaphaelManke 💯
- Remove duplicate callbackstringerror handler (same as stringerror) - Remove callbackStringError test (strings are not valid for Lambda callbacks) - Update test to use stringerror instead of callbackstringerror
59f0dae to
3564271
Compare
|
|
||
| exports.callbackerror = function (event, context, callback) { | ||
| callback(new Error('handler error')); | ||
| exports.callbackerror = async function (event, context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: have exports.callbackerror and exports.callbackError :) This one here is currently a bit misleading. Minor though.
|
Thank you for your contribution @RaphaelManke! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. |
Description
This PR fixes issue #3251 by adding runtime-aware handler support that automatically detects the Node.js version from
AWS_EXECUTION_ENVand adapts handler signatures accordingly.Fixes: #3251
Problem
AWS Lambda deprecated callback-based handlers in Node.js 24 runtime, causing the instrumentation to fail with:
Solution
The instrumentation now automatically detects the Node.js runtime version and adapts:
(event, context)- no callback parameter (respects AWS deprecation)(event, context, callback?)- supports both callback and Promise-based handlers for backward compatibilityI tested it by building a lambda layer with this code version.
Changes
getNodeRuntimeVersion()function to detect Node.js version fromAWS_EXECUTION_ENVenvironment variable_wrapCallback()method for callback support on older runtimesTesting
Backward Compatibility
This change maintains full backward compatibility:
Related Links