fix(instrumentation-aws-lambda): support Node 24 Lambda without baseDir#3319
Draft
overbalance wants to merge 2 commits intoopen-telemetry:mainfrom
Draft
fix(instrumentation-aws-lambda): support Node 24 Lambda without baseDir#3319overbalance wants to merge 2 commits intoopen-telemetry:mainfrom
overbalance wants to merge 2 commits intoopen-telemetry:mainfrom
Conversation
580ccc0 to
474d252
Compare
Comment on lines
+207
to
+208
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const handlerModule = require(filename); |
There was a problem hiding this comment.
How does this behave for ESM handlers ? I assume it'll enter the catch and not cause any issues, but I'd like to make sure given we don't really have test coverage for it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which problem is this PR solving?
Fixes #3314 cc @mduesterhoeft
The
@opentelemetry/instrumentation-aws-lambdapackage doesn't work on Node 24 Lambda when not using Lambda Layers. The handler function is never patched, resulting in no telemetry being collected.Root Cause
On Node 24 Lambda,
require-in-the-middlecannot identify modules when there's nopackage.jsonin the directory hierarchy. This means the instrumentation hooks never fire, regardless of howInstrumentationNodeModuleDefinitionis configured.Solution
Proactively
require()and patch the handler module directly ininit(). The patched module is cached by Node.js, so when Lambda subsequently requires it, it gets the already-patched version.Changes:
init()_patchedHandlerand_handlerFunctionNameproperties to track the patched handlerdisable()override to clean up the proactively patched handler/tmp(truly isolated, nopackage.jsonanywhere in path)Testing Instructions for Issue Reporter (@mduesterhoeft)
To test this fix before it's released, you can install the package directly from this PR branch:
Option 1: Using npm/yarn with git
npm install "git+https://github.com/embrace-io/opentelemetry-js-contrib.git#overbalance/lambda-node24-instrumentation" --workspace=packages/instrumentation-aws-lambdaOption 2: Build locally
git clone https://github.com/embrace-io/opentelemetry-js-contrib.git cd opentelemetry-js-contrib git checkout overbalance/lambda-node24-instrumentationnpm install cd packages/instrumentation-aws-lambda npm run compilebuild/directory to your project'snode_modules/@opentelemetry/instrumentation-aws-lambda/Expected behavior after applying this fix:
You should see the debug log message:
And spans should be created for your Lambda invocations on Node 24.