fix(nodejs): register import in the middle for nodejs24.x runtime#2046
Conversation
8b8447f to
4c18a20
Compare
|
@serkan-ozal @pragmaticivan any thoughts about this? Also tried quickly to add a handler test like the ones we already have. But is difficult to add something "lightweight" since If wanted, I can setup a simple unit test for the loader script. First thought to spy on the |
|
Honestly, the change LGTM, it's simple enough, maybe worth including a comment pointing to the change in the AWS blog post. But other than that, LGTM. |
|
@pragmaticivan That's a good point, it should probably be more clear in the code why we do this check. However I'm not sure there's any official AWS source on this change in the runtime. Rereading the node 24 runtime announcement from AWS I don't see this information in there (or anything hinting at it). @maxday Could you shed any light here, or point to any official resource (if exists) that we can link back to? |
https://aws.amazon.com/blogs/compute/node-js-24-runtime-now-available-in-aws-lambda/
I think that's the breaking change but not really sure |
|
I would think the esm loading is kind of orthogonal to the removal of callback support. The blog post does mention something removal of legacy features in general in the new runtime interface client, so maybe this also involves standardization of module loading logic but I can only guess. |
*Issue #, if available:* *Description of changes:* Patches #352 The Node.js 24 Lambda runtime introduced a new Runtime Interface Client written in TypeScript/ESM, replacing the previous CommonJS implementation. This change broke OpenTelemetry autoinstrumentation for CommonJS handlers because the ESM-based RIC requires ESM loader hooks to be registered for proper module interception, even when the handler itself is CommonJS. This fix detects the Node runtime version and automatically registers the ESM loader (import-in-the-middle) for Node 24 and above, ensuring spans are properly captured and exported to X-Ray regardless of handler type. This aligns with the upstream fix in [opentelemetry-lambda#2046](open-telemetry/opentelemetry-lambda#2046). By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
solves #2034
This change has been tested and fixes aws-lambda instrumentation again for commonjs lambda handlers using node 24 runtime.